Answer the question
In order to leave comments, you need to log in
Is it possible in C++ to create a dynamic mimic class that can mimic another class more than once?
On the example of the game:
There are two classes "Vampire" and "Elf" with their own parameters and methods. And there is the Mimic class , which, when creating an object, does not have a rigid binding to some other class, but during the game it can temporarily turn into a character of another class and get its capabilities .
Is it possible to implement this with C++ classes? (Given that the implementation of all other classes can be tailored just for this purpose.) . Is it possible to make such a binding at least once during the lifetime of an object?
Options through crutches are also of interest.
Answer the question
In order to leave comments, you need to log in
Use a strategy object or delegate objects.
The point is that the class implements its methods through similar delegate methods.
https://ru.wikipedia.org/wiki/%D0%A8%D0%B0%D0%B1%D...
class MimicBase{};
class Vampire : public MimicBase{
public:
Vampire();
Vampire(MimicBase& m) : MimicBase(m){};
};
class Elf : public MimicBase{
public:
Elf();
Elf(MimicBase& m) : MimicBase(m){};
};
MimicBase m1;
Vampire v1(m1);
MimicBase m2(v1); //Обратно
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question