你们显然想要使用多变(因为你想要把一个衍生的阶层只算一个基级)。
但是,每当你想使用多吗).时,你就应当拥有使用点对基的自动化(如果我正确回顾,参考对基准也是有益的)。 假设孩子们公开继承目标,在发言之后是:
- childgoal is-a goal
- a pointer to goal can point to goal or to childgoal (or to any derived class)
- but a goal instance is-NOT-a childgoal
因此,如果你能够把你的童子团划入一个目标(,因为你试图传出一个抽象的“”),那么你就可以把在童年的所有非成员rid掉,从而使你们的原始目标破灭。 我认为这不是你的意图。
If you are afraid about the memory management issue that would arise with classic pointers, you could consider using shared_pointers here :
abstract class goal;
class priority;
class childgoal : public goal;
typedef std::tr1::shared_ptr<goal> goalPtr; //sadly I think std::tr1 is not a multiplatform namespace
multimap<priority, goalPtr> mm;
goalPtr tmpChildGoal(new childgoal()); //always use named shared pointer !
mm.insert(make_pair(priority(), tmpChildGoal);