I have following classes:
class A
{
public:
A();
virtual void doSomething() const;
};
class B : public A
{
public:
B();
void doSomething() const;
};
Then I have function:
void putToList(const A &a)
{
a.doSomething(); // this one depends on what was set as argument A or B class (putToList(A()) or putToList(B()))
std::list<A> As;
As.push_back(a);
As.back().doSomething(); //this always calls doSomething from A
}
My question is that whyafter taking from list, the object is A and how to prevent it change type and make it B if object I passed to function was of class B.