title: Overriding a base class function with different return types
body: <p>I have a base class named Variable:</p>
  
  <pre><code>class Variable
  {
  protected:
      std::string name;   
  public:
      Variable(std::string name="");
      Variable (const Variable&amp; other);
      virtual ~Variable(){};
  };
  </code></pre>
  
  <p>I have several derived classes, such as Int, Bool, String etc. For example:</p>
  
  <pre><code>class Bool: public Variable{
  private:
      bool value;
  
  public:
      Bool(std::string name, bool num);
      ~Bool();
      Bool (const Bool&amp; other);
      bool getVal();
  </code></pre>
  
  <p>Each derived class has a method named getVal() that returns a different type (bool, int, etc.). I want to allow polymorphic behavior for Variable class.<br>
  I tried: <code>void getVal();</code> which seemed wrong and the compiler showed an error: <code>shadows Variable::getVal()</code> which sounds bad.
  I thought of using <code>template &lt;typename T&gt; T getVal();</code> but it didn't help.</p>
  
  <p>Any suggestions? Do I have to use casting for that?</p>
  
  <p>Many thanks...</p>