On 2007-10-25 09:59,
su**************@yahoo.com, India wrote:
Suppose I have
vector<intv;
vector<int>::const_iterator citer = v.begin( );
Here which version of begin( ) is called ? const or non-const
version ?
The non-const version. The reason for this is the fact that v is not
const. Consider the following example:
#include <vector>
void foo(const std::vector<int>& v)
{
std::vector<int>::const_iterator it = v.begin();
}
int main()
{
std::vector<intv;
std::vector<int>::iterator it = v.begin();
std::vector<int>::const_iterator cit = v.begin();
foo(v);
}
In foo() you must use a const_iterator since v is const, in main()
however you can use either since a const_iterator can be constructed
from an iterator. Notice though that I have not found anything in the
standard requiring this, so it might not be portable.
--
Erik Wikström