const 真TM 难啊
const int a = 3;
// easy
const int *b = &a;
const int *x = b;
// *x is a const value
*x = 4;
// error
const int *c = &a;
x = c;
// right
const int* const y = b;
// y is const pointer, and *y is const value
*y = 4;
// error
y = c // error
list<int>::const_reverse_iterator it;// the it can be change, for example: it++; but *it can not be changed
template <class T>
void print(const T * para)
{
typename T::const_iterator it;// here, we must use const_iterator, for the element value in para can't be changed
}
const vector<int> nums;
vector<int>::const_iterator it = nums.begin(); // nums value is const , so we must use const_iterator
转载请注明原文地址: https://ju.6miu.com/read-18108.html