class contains its self pointer
Hi
i want to ask is it normal when I intended to design a class Hierarchy like following?
Code:
class Base {
...
};
class Manager: public Base {
...
void init() { _p = new Derived(); }
private:
Base *_p;
};
class Derived: public Base {
...
};
I am at a situation that I think the only solution is have a reference to DerivedB object in DerivedA.
Just in case someone will curious about how this occurs.
Actually I am using a third party source code. And he defines an entry point which I need to pass a parameter in Base*... Normally, simply derive from Base, and pass the instance to it will be fine. However, I am trying to design a flexible codes, and I want to create a manager class (which I define as above). And make original user defined class in its data member.
However, I think if I design this way, it looks just so unreadable for the maintainer.
I need advice.
Really appreciate for comments. Thx