Hello,
I have a hierarchy of Actions (NonMovingActions and MovinActions each with sub-hierarchies). Actions class has an abstract function.
Code:
class Action
{
public:
Action(Agent& agent, ...):agent(agent),..{}
virtual ~Action(void);
virtual bool run()=0;
...
}
Now I need to store all actions into a single vector:
Code:
class Agent
{
public:
Agent(World& world);
virtual ~Agent(void);
...
vector<Action> actions;
unsigned int actionIterator;
}
It appears that C++ does not allow this (in Java it was possible). Compiler objects that Action class is abstract (and cannot be instantiated?!)
Code:
error C2259: 'Action' : cannot instantiate abstract class
1- May I know what do I not understand here? We cannot refer to sub-class instances with a reference of parent class type?
2- Should I use vector of pointers instead or what?
I appreciate your time and help.
Regards,
Mac