title: Derived class not recognized as covariant
body: <p>So I am creating a Huffman tree, and I am having a hard time overriding a function, and I believe that it is due to a covariance issue. Here is the hierarchy that I am having a hard time with in my code:  </p>
  
  <pre><code>class TreeInterface {
  public:
  
      TreeInterface() {}
      virtual ~TreeInterface() {}
  
      virtual NodeInterface * getRootNode() const = 0;
  };
  
  class Tree : TreeInterface
  {
  public:
      Tree() 
      {}
      virtual ~Tree() 
      {}
  
      Node* getRootNode()
      {
          return treeRoot;
      }
  
      private:
      Node* treeRoot;
  };
  </code></pre>
  
  <p>Those work just fine, but its the next block that has issues.</p>
  
  <pre><code>class HuffmanInterface{
  public:
      HuffmanInterface() {}
      virtual ~HuffmanInterface() {}
  
      virtual bool createTree(string filename) = 0;
  
      virtual string encodeMessage(string toEncode) = 0;
  
      virtual TreeInterface * getTree() = 0;
  
      virtual map&lt;char, string&gt; getEncodings() = 0;
  };
  class Huffman : HuffmanInterface{
  public:
  
      Huffman() {}
      ~Huffman() {}
  
  bool Huffman::createTree(string filename){ }
  
  string Huffman::encodeMessage(string toEncode){ }
  
  string Huffman::decodeMessage(string toDecode){ }
  
  Tree* Huffman::getTree(){ }
  
  map&lt;char, string&gt; Huffman::getEncodings(){ }
  </code></pre>
  
  <p>So the problem is apparently in the getTree() function, giving the following error</p>
  
  <pre><code>invalid covariant return type for ‘virtual Tree* Huffman::getTree()’:
  Tree * getTree();
  </code></pre>
  
  <p>but as far as I know, Tree* should be a valid covariant of TreeInterface*. replacing Tree* with TreeInterface* makes the program compile, but it's not what I need in my actual program. Any help is greatly appreciated!</p>