vector help talks about front()
Returns a reference to the first element in a vector container. Unlike the vector::begin member, which returns an iterator to the same element, this function returns a direct link.
Vector help says begin()
Returns an iterator referring to the first element in a vector container. Note that unlike the vector::front member, which returns a reference to the first element,> this function returns a random access iterator.
And this code outputs:
char arr[] = { 'A', 'B', 'C' }; vector<char> vec(arr, arr+sizeof(arr)); cout << "address of vec.front() " << (void*)&vec.front() << endl; cout << "address of vec.begin() " << (void*)&vec.begin() << endl;
address vec.front() 00401F90 address vec.begin() 0030F494
I don’t understand what “direct link” means? In the case of begin() not random access iterator just a pointer ?
Can anyone point out the difference?
source share