I have a problem regarding multiple inclusion of header file in C++ code.
Say for example, I have three classes X, Y, Z. X and Y are derived from base class Z. And I want to create an instance of X in Y. The code will go like this.
class Z { …some code… };
class X: public Z { …some code… }; //here #include header of class Z added
class Y: public Z //here #include header of class Z added as well as of X class
{
private:
X* mX; //instance of X
…some code…
};
So in this multiple definition of all methods of base class arises. How can I cope with this problem?