This may sound like a newbie question. How do I call a member function of an object stored in a vector ? Supposedly, I have this class:
class A {
public:
void foo() {
std::cout << "Hello World"; }
};
Then I store some objects in a vector:
std::vector<A*> objects;
A* b;
A* c;
A* d;
objects.push_back(b);
objects.push_back(c);
objects.push_back(d);
Now I want to create a loop, in which every object stored in the vector would call it's own foo() function. How should I do this ? At first I thought I could just do something like this:
objects[2].foo();
But it seems that I can't do it like this.