Say I have class A and class B as follows:
Then if I execute the following code:Code:class A { public: void dostuff(void) { cout<<"A is doing stuff"<<endl; } }; class B : public A{ public: void dostuff(void) { cout<<"B is doing stuff"<<endl; } };
The output will be:Code:vector<A*> alist; alist.push_back(new A()); alist.push_back(new B()); for(int i=0;i<2;++i) { (alist.at(i))->dostuff(); }
My problem is that I want B's dostuff() function to get called the second time instead of A's... any way to do that?Code:A is doing stuff A is doing stuff
Edit: On an unrelated note, how do some of you manage to get the syntax highlighting in your code tags?