Again for learning purposes, I'm creating a vector of pointers to string and then access the underlying strings. After a little trial and error, I produced the following (showing where I read the vector)...
It works and I understand why. But I do have a couple of questions:Code:/* ... */ for(vector<string*>::const_iterator ster = svec.begin(); ster != svec.end(); ++ster) cout << **ster << "\t" << (*ster)->size() << endl; /* ... */
My main problem was achieving (*ster)->size, despite the fact I'm already somewhat familiar with the -> operator from past exercises. Everything else went like a breeze. But although I do understand why it works (dereference the iterator ster, then dereference the resulting pointer to string, and then apply the dot operator to resulting string class), I would like to understand this better. I'm trying to expand that statement to just the * and . operators.
*(*(ster)).size() is not doing it. I cannot fathom why.
I'm wondering about size_type. Should these follow strictly the same type as the underlying vector only for aesthetic and logical reasons, or are there any cases in which not doing it may produce bad results?
I could for instance, not have used iterators on the code above and use instead subscripts. The funny thing is that the control flag could have been either vector<string*>::size_type i = 0 or vector<int>::size_type i = 0 and I would still have a perfectly valid, error and warning-free code.
I'm not thinking being lazy about it. But would like to know if there can be any side-effects for not following what seems to be the wisest choice (declare size_type as the same type of the underlying vector)