October 20, 2008
A const_iterator is not a const iterator. That is,
const vector<int>::iterator it;
and
vector<int>::const_iterator it;
are different. The first type (const iterator) does not allow any kind of modification of the iterator as well as the contents. That is, both
++it;
and
*it = 40 are illegal.
The second type(const_iterator) allows modification of the iterator, but prevents the contents from getting modified.
So,
++it is legal whereas *it = 40 is illegal.
#include<vector>
using namespace std;
int main()
{
vector<int> myVector;
myVector.push_back(10);
myVector.push_back(20);
vector<int>::const_iterator it = myVector.begin();
++it; // Legal
*it = 40; // Illegal
return 0;
}
Leave a Comment » |
C++, VC++ 2005, gcc | Tagged: C++, C++ stl, const, const_iterator, iterator, vector |
Permalink
Posted by cppkid
October 10, 2008
At times, I had been annoyed that the watch window was not showing the whole contents of a pointer array until I found the trick.
Put in the watch window
Starting Address, No of elements to be shown

Please note that in the screen shot attached, the pointer has not been deleted. This may cause memory leaks. I’m sorry that I saw it only now.
Leave a Comment » |
C++, VC++ 2005 | Tagged: contents of pointer, debug pointer, pointer as array, watch pointer |
Permalink
Posted by cppkid
October 9, 2008
Use the option -Wunused with gcc.
gcc MyFile.cpp -Wunused
Leave a Comment » |
C++, gcc | Tagged: C++, gcc, Linux, unused parameters, warn on unused parameters |
Permalink
Posted by cppkid