Re: Pointers as iterators; vector<string> representation...
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:gf2jh4$5cm$1@news.datemas.de...
barcaroller wrote:
1. If I pass pointers (char*) as iterators to an STL algorithm and the
return value is an iterator, can I convert that iterator to a pointer?
If yes, how?
For most of the standard algorithms, the return value type is the same as
the one you pass. It's already a pointer, no need to convert. Test it,
you'll see.
Just an added note, the way to convert an iterator to a pointer is to take
the address of the dereferenced iterator. I.E.
&(*it) would be a pointer to the item if it is an iterator or a pointer.
2. What is the internal representation of vector<string>?
Implementation-defined.
Will the vector
contain the string objects or will it contain pointers/references to the
string objects? The reason I ask is that it is not clear to me how the
v.reserve() and &v[0] operations would work for a vector<string>.
The vector will contain a dynamic array of 'string' objects. The
'reserve' operation allocates the array capable of containing future
'string' objects (which will be constructed using 'placement new', most
likely). Taking the address of v[0] (which returns the reference to the
very first object in the inner array) will give you the starting address
of the inner array. What's there to [not] understand? Now, you probably
need to understand how 'string' works, as well. Do you?
As an added note you can find your implementation of std::string on your
system. Try opening up your string. file and taking a look. It can get
pretty esoteric but if you can understand that code you will be well on your
way to understanding C++.