title: How to prevent a pointer of base class to point to derived class?
body: <p>I have the following problem that looks like this.</p>
  
  <pre><code>class Animal
  {
     void* value;
     public:
     Animal() {}
     void* getValue() {return value;} 
  }
  
  class IntAnimal : private Animal
  {
    public:
    IntAnimal() {}
    int getValue() {return (*(int*)Animal::getValue());}
  }
  </code></pre>
  
  <p>Basically the base class return void*, but the derived class return a regular type (int, double, char, etc).</p>
  
  <p>I need to make either:</p>
  
  <ol>
  <li><p>We can do: <code>Animal* intAnimal = new IntAnimal(); int x = intAnimal-&gt;getValue();</code> I think this is not possible.</p></li>
  <li><p>Prevent others from doing: <code>Animal* intAnimal = new IntAnimal();</code></p></li>
  </ol>
  
  <p>How do I prevent others from doing (2) ? Thank you.</p>
  
  <p>Edit: yes this is a terrible design and I should use template. But, is there any other way to solve this problem?</p>