A stupid typo mistake

A stupid typo mistake

Welcome to my blog. Help yourself.
----- perrin

2018-11-03 14:18



int left=0,right=0;
....
//left and right both changed 
....

// init them in a for loop first sentence in a wrong style
for(int i=0,left=1;...;...){   //the wrong way, a new loop local var left created
...
...//change here to left is to to local variable not the outside var left
}

int i=0;
for( i=0,left=1;...;...){   //the correct way
...
...//change here to left is to to the outside var left
}


This typo mistake is easy forgotten.  Especially when a new block local var created without our attention.

A similar case is that global var will be shadowed by local var.


int count=1;

int calculate(int x){
    int count=0;
    for(int i=0;i<x;++i){
        count+=1
    }
    return count;
}

We can use namespace to avoid shadowing.


nampspace my_ns{
    int count=0;
}

int calculate(int x){
    int count=0;
    for(int i=0;i<x;++i){
        count+=1
    }
    return my_ns::count;
}

 

wwwww eeeeee
test ------ 2019-01-20 23:03, 36.102.208.84, 476461917@qq.com.

Commenter Name
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
Commenter Name
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
Commenter Name
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
Search
Page view info
{'ip': '3.215.182.36', 'lat_lon': (41.890251, 12.492373), 'city': 'Rome', 'pv': 65422, 'cur_pv': 126, 'cur_daily_pv': 2, 'ur_pv': 3, 'ur_cur_all': 1, 'ur_today_all': 3, 'ur_today_cur': 1, 'daily_pv': 408, 'daily_ip': 284, 'whole_ip': 10334, 'ip_delta': 17}
AMap
Baidu Map