0

I'm working on a project that involves Huffman Trees. I have split my files into headers etc.

I have declared a method for allocating tree nodes in the HuffmanTree.h header file, and I am implementing it in the HuffmanTree.cpp file.

I am still getting an unresolved external, however.

Inside the header:

private:

    HuffTreeNode* root;
    int weight = -1;                                                                        // in-class initialization of the data members

    friend ostream& operator<<(ostream& out, const HuffmanTree& tree);
    friend class Comparator;

    bool onlyLeaf(HuffTreeNode* root);
    void encode(HuffTreeNode* root, string str, unordered_map<char, string>& huffMap);
    void decode(HuffTreeNode* root, int& i, std::string str);
    
    
    HuffTreeNode* allocateNode(char letter, int charFreq, HuffTreeNode* left, HuffTreeNode* right);

Inside the .cpp:

// Allocating the new node to the Huffman Tree
HuffTreeNode* HuffmanTree::allocateNode(char letter, int charFreq, HuffTreeNode* left, HuffTreeNode* right)
{

    HuffTreeNode* node = new HuffTreeNode();

    node->myChar = letter;

    node->myFrequency = charFreq;

    node->myLeft = left;

    node->myRight = right;

    return node;

}

The error:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "public: __thiscall HuffTreeNode::HuffTreeNode(void)" (??0HuffTreeNode@@QAE@XZ) referenced in function "private: class HuffTreeNode * __thiscall HuffmanTree::allocateNode(char,int,class HuffTreeNode *,class HuffTreeNode *)" (?allocateNode@HuffmanTree@@AAEPAVHuffTreeNode@@DHPAV2@0@Z)  CA2 C:\Users\me\source\repos\proj\HuffmanTree.obj   1   

Any help would be appreciated.

drayk73019
  • 17
  • 5
  • `HuffTreeNode::HuffTreeNode` is the name of a constructor. You're missing one. – Mat Apr 24 '21 at 08:55
  • `HuffTreeNode::HuffTreeNode(void)` -- The linker error tells you what the issue is. That function is missing. – PaulMcKenzie Apr 24 '21 at 08:55
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ulrich Eckhardt Apr 24 '21 at 09:13

0 Answers0