Lets say i have a television class and BigTelevision class
class television
{
protected:
int a;
...
}
class BigTelevision:public television
{
private:
int b;
...
}
I want to contain a collection of a mixed of television and BigTelevision, what options do i have.
I know one way is to use array but the problem with this is that if i declare an array of television type to store them the additional attributes(eg int b) of BigTelevision would be lost.
How can i work around this ?
You have to store base class pointers or base class smart pointers ore use a pointer collection like boost:ptr_vector.
You can now use different object through a common interface (Polymorphism).