class Base
{
protected:
string m_Name;
public:
virtual string Name() { return m_Name; }
virtual string Type() = 0;
virtual bool isEqual(Base* rhs) = 0 ;
};
I have an abstract class Base. Different class in my code inherit from this Base class. I store these object in a container (a vector of pointer of Base)
struct Container
{
vector<Base*> vec;
int Count() { return vec.size(); }
Base* operator[](int i)
{
if (i<=0) throw anexception;
if (i>=vec.size()) throw anexception;
return vec[i];
}
};
I overloaded the operator [], but I only manage to return a pointer. Is there a way so that I can return the object vec[i] (which is of a type that inherit from Base)?