// suppose we have a vector that takes a pointer to an object of abstract class // like this std::vector<foo*> myVector(5); // declared a vector // a print method just prints data of each object in the vector for(int a = 0; a < myVector.size()-1; a++){ myVector.at(a)->print(); } // this works but using an iterator doesnt. Why? // suppose we have this traversal for(std::vector<foo*>::iterator a = myVector.begin(); i != myVector.end(); ++a){ // trying to print out each object cout << *a << endl; // of course it won't work why? first can't even get to print function // second trying to access the object of an abstract class by derefencing the pointer. // Oh and this, by dereferencing i cout the address of it but can't print out with print function }
for(int a = 0; a < myVector.size()-1; a++){ myVector.at(a)->print(); }
Quote:It goes from zero to size - 1
size-1
size-2
cout << (*a)->print() << endl;
*a
foo
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)