Random Post: God Mode In Windows 7
RSS .92| RSS 2.0| ATOM 0.3
  • Home
  • About
  •  

    What is const_iterator

    October 20th, 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;
    
    }
    

    How To Watch Pointer As An Array

    October 10th, 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.


    How To Make gcc Warn You About Unused Variables

    October 9th, 2008

    Use the option -Wunused with gcc.

    gcc MyFile.cpp -Wunused