title: Multiple constructors in a class
body: <p>I have class A,B,C,D which all have a member of class X in it. I have another class called class P.
  <p>In my class A I create an instance of class P as well. In class P I need to access the X instance of A and a method of A (this method is available in class B,C,D as well with the same method signature and parameters), therefore I pass class A to class P while initializing class P.</p>
  
  <p>so The code looks like;</p>
  
  <pre><code>class P;
  class A{
  public:
      X x;
      P *p;
  
      A(){
          x = new X();
      };
  
      void setData(){
          p =  new P(this);
      }
  };
  
  
  class P{
  public:
      A *a;
      P(A *_A){
          a = _A;            
          a-&gt;x.resetVal();
      }
  }; 
  </code></pre>
  
  <p>Now I need to create instances of P in class B,C,D as well and pass instances of those classes to P.
  <p>To my knowledge to achieve this I must either make A,B,C,D a child class of a new class (class Parent) and set the constructor of class P to accept class Parent instance, or I must create separate constructors for classes A,B,C,D in class P.</p>
  
  <pre><code>class Parent {
      X x;
  }
  class P;
  class A:: Parent{
      ...........//code
  };
  
  
  class P{
  public:
      Parent *prnt;
      Impl(Parent *prnt){
          .........//code
      }
  };
  
  ---------------------- OR -------------------------
  
  class P{
  public:
      A *a;
      B *a;
      C *a;
      D *a;
  
      Impl(A *_A){
          .............//code
      }
  
      Impl(B *_B){
          .............//code
      }
  
      Impl(C *_C){
          .............//code
      }
  
      .............//code
  };
  </code></pre>
  
  <p>I do not want to change class A,B,C,D because that would be complicated as those classes were not written by me. Is there another way to achieve this other than the two above methods?
  <p>Any help would be appreciated. Thanks.</p>