title: C++, virtual inheritance, strange abstract class + clone problem
body: <p>Sorry for the larger amount of the source code. There three abstract classes P, L, PL. The third class PL is derived from classes P and L using the virtual inheritance:</p>
  
  <pre><code>template &lt;typename T&gt;  //Abstract class
  class P
  {
  
      public:
              virtual ~P() = 0;
      virtual P &lt;T&gt; *clone() const  = 0;
  };
  
  template &lt;typename T&gt;
  P&lt;T&gt;::~P() {}
  
  template &lt;typename T&gt;
  P&lt;T&gt; * P &lt;T&gt;:: clone() const { return new P &lt;T&gt; ( *this ); }
  
  template &lt;typename T&gt;  //Abstract class
  class L
  {
      public:
              virtual ~L() = 0;
      virtual L &lt;T&gt; *clone() const = 0;
  };
  
  template &lt;typename T&gt;
  L&lt;T&gt;::~L() {}
  
  template &lt;typename T&gt;
  L&lt;T&gt; *L &lt;T&gt; ::clone() const { return new L &lt;T&gt; ( *this );}
  
  template &lt;typename T&gt;
  class PL: virtual public P &lt;T&gt;, virtual public L &lt;T&gt;  //Abstract class
  {
      public:
              PL() : P &lt;T&gt;(), L&lt;T&gt;() {}
      virtual ~PL() = 0;
      virtual PL &lt;T&gt; *clone() const  = 0;
  };
  
  template &lt;typename T&gt;
  PL&lt;T&gt;::~PL() {}
  
  template &lt;typename T&gt;
  PL&lt;T&gt; * PL &lt;T&gt; :: clone() const { return new PL &lt;T&gt; ( *this );}
  </code></pre>
  
  <p>Every class has its own implementation of the clone method.</p>
  
  <p>Two next classes PA, PC are derived from class P using the virtual inheritance:</p>
  
  <pre><code>template &lt;typename T&gt;
  class PC : virtual public P &lt;T&gt;
  {
      public:
              PC() : P &lt;T&gt; () {}
              virtual ~PC() {}
              virtual PC &lt;T&gt; *clone() const {return new PC &lt;T&gt; ( *this );}
  };
  
  template &lt;typename T&gt;
  class PA : virtual public P &lt;T&gt;
  {
      public:
              PA() : P &lt;T&gt; () {}
              virtual ~PA() {}
              virtual PA &lt;T&gt; *clone() const {return new PA &lt;T&gt; ( *this );}
  };
  </code></pre>
  
  <p>The last two classes PCL and PAL are dirived using the virtual inheritance from PC and PL , PA and PL.</p>
  
  <pre><code>template &lt;typename T&gt;
  class PCL : public PC &lt;T&gt;, public PL &lt;T&gt;
  {
      public:
              PCL() : P &lt;T&gt; (), PC &lt;T&gt; (), PL &lt;T&gt; ()  {}
              virtual ~PCL() {}
              virtual PCL &lt;T&gt; *clone() const {return new PCL &lt;T&gt; ( *this );}
  };
  
  template &lt;typename T&gt;
  class PAL : public PA &lt;T&gt;, public PL &lt;T&gt;
  {
      public:
              PAL() : P &lt;T&gt; (), PA &lt;T&gt; (), PL &lt;T&gt; () {}
              virtual ~PAL() {}
              virtual PAL &lt;T&gt; *clone() const {return new PAL &lt;T&gt; ( *this );}
  </code></pre>
  
  <p>};</p>
  
  <p>There is the diagram of the class dependencies:</p>
  
  <pre><code>.......... P .... L.....
  ........../|\..../......
  ........./.|.\../.......
  ......../..|..\/........
  .......PC..PA..PL.......
  .......|...|.../|.......
  .......|...|../.|.......
  .......|...PAL..|.......
  .......|........|.......
  .......PCL_____/........  
  </code></pre>
  
  <p>Please, do not discuss this proposal :-))). I have the following 3 questions:</p>
  
  <p>1) Was this class dependency rewritten in C++ correctly (first of all the placemement of "virtual")?</p>
  
  <p>2) I am not sure what is wrong, see the code, please:</p>
  
  <pre><code>int main(int argc, _TCHAR* argv[])
  {
  PCL &lt;double&gt; * pcl = new PCL &lt;double&gt;(); //Object of abstract class not allowed
  PAL &lt;double&gt; * pal = new PAL &lt;double&gt;(); //Object of abstract class not allowed
  PL &lt;double&gt; *pl1 = pcl-&gt;clone(); //Polymorphism
  PL &lt;double&gt; *pl2 = pal-&gt;clone(); //Polymorphism
  return 0;
  } 
  </code></pre>
  
  <p>It is not possible to create new objects of PAL / PCL classes, both classes are marked as abstract. But they are not abstract. Where is the problem?</p>
  
  <p>3) Is it possible to use polymorphism together with clone() method? See the code above, please...</p>
  
  <p>Thanks for your help...</p>
  
  <hr>
  
  <p><strong>UPDATED QUESTION</strong></p>
  
  <p>I corrected the code. But the following error using VS 2010 compiler appear:</p>
  
  <pre><code>template &lt;typename T&gt;  //Abstract class
  class P
  {
      public:
      virtual ~P() = 0;
      virtual P &lt;T&gt; *clone() const  = 0;
  };
  
  template &lt;typename T&gt;
  P&lt;T&gt;::~P() {}
  
  template &lt;typename T&gt;
  P&lt;T&gt; * P &lt;T&gt;:: clone() const { return new P &lt;T&gt; ( *this ); }
  
  
  template &lt;typename T&gt;  //Abstract class
  class L
  {
      public:
      virtual ~L() = 0;
      virtual L &lt;T&gt; *clone() const = 0;
  };
  
  template &lt;typename T&gt;
  L&lt;T&gt;::~L() {}
  
  template &lt;typename T&gt;
  L&lt;T&gt; *L &lt;T&gt; ::clone() const { return new L &lt;T&gt; ( *this );}
  
  
  template &lt;typename T&gt;
  class PL: virtual public P &lt;T&gt;, virtual public L &lt;T&gt;  //Abstract class
  {
      public:
              PL() : P &lt;T&gt;(), L&lt;T&gt;() {}
      virtual ~PL() = 0;
      virtual PL &lt;T&gt; *clone() const  = 0; 
  };
  
  template &lt;typename T&gt;
  PL&lt;T&gt;::~PL() {}
  
  template &lt;typename T&gt;
  PL&lt;T&gt; * PL &lt;T&gt; :: clone() const { return new PL &lt;T&gt; ( *this );}
  
  
  template &lt;typename T&gt;
  class PC : virtual public P &lt;T&gt;
  {
      protected:
              T pc;
      public:
              PC() : P &lt;T&gt; () {}
      virtual ~PC() {}
              virtual PC &lt;T&gt; *clone() const {return new PC &lt;T&gt; ( *this );}
  };
  
  template &lt;typename T&gt;
  class PA : virtual public P &lt;T&gt;
  {
      public:
              PA() : P &lt;T&gt; () {}
      virtual ~PA() {}
              virtual PA &lt;T&gt; *clone() const {return new PA &lt;T&gt; ( *this );}
  };
  
  template &lt;typename T&gt;
  class PCL : public PC &lt;T&gt;, public PL &lt;T&gt;
  {
  public:
              PCL() : P &lt;T&gt; (), PC &lt;T&gt; (), PL &lt;T&gt; () {}
              virtual ~PCL() {}
              virtual PCL &lt;T&gt; *clone() const {return new PCL &lt;T&gt; ( *this   );}
  }; //Error using VS 2010: Error 1   error C2250: 'PCL&lt;T&gt;' : ambiguous inheritance of 'PC&lt;T&gt; *P&lt;T&gt;::clone(void) const'
  
  
  template &lt;typename T&gt;
  class PAL : public PA &lt;T&gt;, public PL &lt;T&gt;
  {
  public:
              PAL() : P &lt;T&gt; (), PA &lt;T&gt; (), PL &lt;T&gt; ()  {}
              virtual ~PAL() {}
              virtual PAL &lt;T&gt; *clone() const {return new PAL &lt;T&gt; ( *this );}
  }; //Error VS 2010: Error   1   error C2250: 'PAL&lt;T&gt;' : ambiguous inheritance of 'PA&lt;T&gt; *P&lt;T&gt;::clone(void) const'
  
  
  int main(int argc, char* argv[])
  {
  PCL &lt;double&gt; * pcl = new PCL &lt;double&gt;();
  PAL &lt;double&gt; * pal = new PAL &lt;double&gt;();
  PL &lt;double&gt; *pl1 = pcl-&gt;clone();
  PL &lt;double&gt; *pl2 = pal-&gt;clone();
  return 0;
  }
  </code></pre>
  
  <p>Maybe i overlooked something... But g++ compiles this code OK.</p>