C++ casting a class instance to another instance throws: No suitable defined conversion from class to class2
<p>Here is my code:</p>

<pre><code>using namespace std;

class HuffmanTree
{
public: 
    int frequency;

    HuffmanTree(){}
    HuffmanTree(int freq)
    {
        frequency = freq;
    }

    int compareTo(HuffmanTree tree)
    {
        return frequency - tree.frequency;
    }
}

class HuffmanLeaf : public HuffmanTree
{
public:
    char value;

    HuffmanLeaf(int freq, char val)
    {
        HuffmanTree(freq);
        value = val;
    }
}

class HuffmanNode : public HuffmanTree
{
public:
    HuffmanTree left, right;

    HuffmanNode(HuffmanTree l, HuffmanTree r)
    {
        HuffmanTree(l.frequency + r.frequency);
        left = l;
        right = r;
    }
}

class HuffmanCode
{
    static HuffmanTree buildTree(int charFreqs[])
    {
        priority_queue&lt;HuffmanTree&gt; pq;

        for(int i = 0; i &lt; sizeof(charFreqs)/sizeof(char); i++)
        {
            if(charFreqs[i] &gt; 0)
                pq.push(HuffmanLeaf(charFreqs[i], (char)i));
        }
        while (pq.size() &gt; 1)
        {
            // two trees with least frequency
            HuffmanTree a = pq.top();
            pq.pop();
            HuffmanTree b = pq.top();
            pq.pop();

            // put into new node and re-insert into queue
            pq.push(HuffmanNode(a, b));
        }
        HuffmanTree c = pq.top();
        pq.pop();
        return c;
    }
}

static void printCodes(HuffmanTree tree, string prefix) {
    //assert tree != null;
    HuffmanTree* baseClass;
    HuffmanLeaf* leafClass;
    HuffmanNode* nodeClass;
    if (typeid(*baseClass) == typeid(HuffmanLeaf)) 
    {
        HuffmanLeaf leaf = (HuffmanLeaf)tree;

        // print out character, frequency, and code for this leaf (which is just the prefix)
        cout&lt;&lt;leaf.value&lt;&lt;"\t"&lt;&lt;leaf.frequency&lt;&lt;"\t"&lt;&lt;prefix;
    }
    else if (typeid(*baseClass) == typeid(HuffmanNode)) 
    {
        HuffmanNode node = (HuffmanNode)tree;

        // traverse left
        prefix.append("0");
        printCodes(node.left, prefix);
        prefix.erase(prefix.length()-1);

        // traverse right
        prefix.append("1");
        printCodes(node.right, prefix);
        prefix.erase(prefix.length()-1);
    }
}
</code></pre>

<p>I have no idea how to fix the issue where the lines fail</p>

<pre><code>HuffmanNode node = (HuffmanNode)tree;
HuffmanLeaf leaf = (HuffmanLeaf)tree;
</code></pre>

<p>I know it has to do with type conversion, and i'd done research on dynamic_cast, static_cast, and the other two, I can't seem to figure out what it's asking for. Any help would be appreciated. And if there are any other issues that you spot, please let me know.</p>
