I'm currently writing some code that iterates through a vector and calls a simple print method for every element within that vector; however, I have very limited experience with vectors and I'm having some issues getting the compiler to accept this one particular segment of code:
std::vector<Buyer *>:: iterator it;
Buyer *b;
for(it = buyers->begin(); it != buyers->end(); ++it) {
b = *it;
cout << b->getName();
}
where buyers is a vector containing Buyer pointers. I'd much rather use an array for this purpose, but as I'm required to use a vector for this particular point, I'm unsure of how to iterate through it and ended up trying an iterator to get through.
The error message that springs up is:
Retailer.cpp:37:17: error: base operand of ‘->’ is not a pointer
for(it = buyers->begin(); it != buyers->end(); ++it) {
^
Retailer.cpp:37:40: error: base operand of ‘->’ is not a pointer
for(it = buyers->begin(); it != buyers->end(); ++it) {
From what I understand, there's apparently a pointer somewhere in that mess I'm not dereferencing, but I'm not sure which element that is or where I should dereference it... any ideas for a programmer who's had little experience with c++ vectors/iterators?
buyers?