提问人:drayk73019 提问时间:4/24/2021 更新时间:4/24/2021 访问量:50
使用霍夫曼代码解析的未解析外部 C++
Unresolved external C++ with huffman code
问:
我正在做一个涉及霍夫曼树的项目。我已将文件拆分为标题等。
我已经在 HuffmanTree.h 头文件中声明了分配树节点的方法,并在 HuffmanTree.cpp 文件中实现了它。
但是,我仍然收到一个未解决的外部问题。
标题内:
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);
在.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;
}
错误:
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
任何帮助将不胜感激。
答: 暂无答案
评论
HuffTreeNode::HuffTreeNode
是构造函数的名称。你错过了一个。HuffTreeNode::HuffTreeNode(void)
-- 链接器错误告诉您问题所在。缺少该功能。