title: Alternatives of template classes in C++?
body: <p>Is it possible to a define generic classes without using templates in C++. I have written a compiler for a language which generates C++ code but I haven't included template construct in my language.</p>
  
  <p>What I want to know is it possible to generic classes in my language with my language as well.</p>
  
  <p>The tried to do it by the following way:</p>
  
  <p>For implementing a new data structure (eg. stack) I declare its type as “Data”, an empty class, and imposed a restriction on the user to first define a new class (eg. myData) which extends Data and use only myData objects with the data structure.</p>
  
  <p>Stack.h definition:</p>
  
  <pre><code>#ifndef STACK_H
  #define STACK_H
  
  #include &lt;stack&gt;
  
  class Data{};
  
  class Stack {
  private:
      std::stack&lt;Data*&gt; st;
  public:
      bool empty()    {return st.empty();}
      int size()  {return st.size();}
      void pop()  {st.pop();}
      Data* top() {return st.top();}
      void push(Data &amp;e) {st.push(&amp;e); }
  };
  
  #endif
  </code></pre>
  
  <p>Expected definition of “myData” from user:</p>
  
  <pre><code>class myData: public Data{
  public:
      int a;
      myData (int A): a(A){}
      myData (){}
      myData (const Data&amp; x) {
      }
  
      myData&amp; operator= (const Data&amp; x) {
      }
      int getData(){return a;}
  };
  </code></pre>
  
  <p>Tried to run the following main():</p>
  
  <pre><code>int main(){
      stack&lt;Data*&gt; st;
      myData A(10);
      st.push(&amp;A);
      printf("%u\n", &amp;A);
      printf("Size: %d\n", (int)st.size());
  
      myData B;
      Data *C = (st.top());
      B = *((myData*)C);
      printf("%u\n", C);
      printf("%d\n", B.getData());
  
      return 0;
  }
  </code></pre>
  
  <p>I want to know is there any better apporoach to try do the same which is more organized and proper. You can assume my language to be (c++ - {template classes}).</p>