Mixing Generic Programming with Polymorphism
<p>I have seen a few articles on generic programming and how you should never use virtual functions and templates together. I understand this idiom, as templates are decided at compilation, where virtual functions are not chosen until run-time (over simplification).  </p>

<p>However, I have a bit of code that uses OO style and Generic style together and it seems to work the way I want. </p>

<p>My Question:</p>

<p>Is the following design bad practice. Mixing Polymorphism and Generic Code?</p>

<p>Is there any pit falls with my code below. (I know I should not inherit data members, but I have :-/).</p>

<pre><code>#ifndef BaseTemplate_H
#define BaseTemplate_H

#include &lt;vector&gt;

template&lt; class T &gt;
class BaseTemplate {

 public:

  typedef std::vector&lt;T*&gt; pVT;

  BaseTemplate(){}
  virtual ~BaseTemplate(){};
  virtual void Process()=0;
  const pVT&amp; getContainer(){ return m_pContainer; }

 protected:

  pVT m_pContainer;

 private:

  BaseTemplate( const BaseTemplate&amp; cpy );
  BaseTemplate&amp; operator=( const BaseTemplate&amp; rhs);



};

#endif
</code></pre>

<p>I inherit from the base class first by telling the base template what type I would like when inheriting.
This will allow me two inherit for multiple types, which I want to keep separate in my design. </p>

<pre><code>#ifndef DerClassA_H
#define DerClassA_H

#include &lt;iostream&gt;
#include "BaseTemplate.h"

class DerClassA: public BaseTemplate&lt;int&gt; {

 public:

 DerClassA(){}
 virtual ~DerClassA(){}
 virtual void Process(){
   std::cout &lt;&lt; "HELLO I AM: DerClassA" &lt;&lt; std::endl;
 }//This will push_back objects to m_pContainer

 private:

 DerClassA( const DerClassA&amp; cpy );
 DerClassA&amp; operator=( const DerClassA&amp; rhs);



};

#endif


#ifndef DerClassB_H
#define DerClassB_H

#include &lt;iostream&gt;
#include "DerClassA.h"

class DerClassB: public DerClassA {

 public:

 DerClassB(){}
 virtual ~DerClassB(){}
 virtual void Process(){
   std::cout &lt;&lt; "HELLO I AM: DerClassB" &lt;&lt; std::endl;
 }//This will push_back objects to m_pContainer

 private:

  DerClassB( const DerClassB&amp; cpy );
  DerClassB&amp; operator=( const DerClassB&amp; rhs);



};

#endif

#include "DerClassA.h"
#include "DerClassB.h"

int main()
{

  BaseTemplate&lt;int&gt; *pClassA = new DerClassA();
  pClassA-&gt;Process();

  DerClassA *pClassB = new DerClassB();
  pClassB-&gt;Process();

  delete pClassA;
  delete pClassB;

  return 0;
}
</code></pre>
