I'll start by posting the code i currently have. I tried to reduce it as much as possible but since i'm not so experienced with C++ i don't know if i may have left out to much or just showing to much code.
class IBehavior {
public:
virtual void Fly() = 0;
};
class BehaviorA : public IBehavior {
void DoIt() {
cout << "Behavior: A\n";
};
};
class BaseOfAB {
IBehavior behavior;
void DoIt() {
behavior.DoIt();
};
};
class A : public BaseOfAB {
A() {
BehaviorA behavior;
};
};
int main()
{
A objA;
objA.DoIt();
return 0;
}
What i'm trying to do is define the property of its behavior in a class that implements the abstract class. Then i want class BaseOfAB to have an object which will be declared in the subclass. And by doing so the behavior.DoIt() should have the behavior that is implemented in the class BehaviorA. Does anyone know how to do this cause i can't seem to figure it out?
Thanks in advance.
Kind regards,
Bob
Aucun commentaire:
Enregistrer un commentaire