编译BST源代码时得到LNK2019和LNK1120

时间:2018-10-23 13:50:56

标签: c++ class linker lnk2019

此代码旨在创建一个二进制搜索树类。

#pragma once
#include "Dictionary.h"
#include "BSTNode.h"


template <typename Key, typename E>
class BST : public Dictionary<Key, E>
{
private:
    BSTNode<Key, E> * root;
    int node_count;

    void ClearHelp(BSTNode<Key, E>*);
    BSTNode<Key, E>* InsertHelp(BSTNode<Key, E>*, const Key&, const E&);
    BSTNode<Key, E>* DeleteMin(BSTNode<Key, E>*);
    BSTNode<Key, E>* GetMin(BSTNode<Key, E>*);
    BSTNode<Key, E>* RemoveHelp(BSTNode<Key, E>*, const Key &k);
    E FindHelp(BSTNode<Key, E>*, const Key&) const;
    void PrintHelp(BSTNode<Key, E>*, int) const;
public:
    BST() { root = nullptr; node_count = 0; }
    ~BST() { ClearHelp(root); }

    void Clear() override { ClearHelp(root); root = nullptr; node_count = 0; }
    void Insert(const Key& k, const E& e) override
    {
        root = InsertHelp(root, k, e);
        node_count++;
    }
    E Remove(const Key& k) override
    {
        E tmp = FindHelp(root, k);
        if (tmp != 0)
        {
            root = RemoveHelp(root, k);
            node_count--;
        }
        return tmp;
    }

    E RemoveAny() // Delete min value
    {
        if (root != nullptr)
        {
            E temp = root->Element();
            root = RemoveHelp(root, root->key());
            return temp;
        }
        else return 0;
    }

    E Find(const Key &k) override { return FindHelp(root, k); }
    int size() override { return this->node_count; }
    void Print() const
    {
        if (root == nullptr)
            std::cout << "The BTS is empty!\n";
        else
            PrintHelp(root, 0);
    }
};

尝试在VS2017中编译代码后出现这些错误:

  

1> main.obj:错误LNK2019:无法解析的外部符号“私有:无效   __thiscall BST :: ClearHelp(class BSTNode *)“(?ClearHelp @?$ BST @ HH @@ AAEXPAV?$ BSTNode @ HH @@@ Z)   “公共:虚拟__thiscall BST ::〜BST(void)”   (?? 1?$ BST @ HH @@ UAE @ XZ)

     

1> main.obj:错误LNK2019:无法解析的外部符号“私有:类   BSTNode * __thiscall BST :: InsertHelp(class   BSTNode *,int const&,int const&)“   在(InsertHelp @?$ BST @ HH @@ AAEPAV?$ BSTNode @ HH @@ PAV2 @ ABH1 @ Z)中引用   函数“公共:虚拟无效__thiscall BST :: Insert(int   const&,int const&)“(?Insert @?$ BST @ HH @@ UAEXABH0 @ Z)

     

1> D:\ 05Development \ 04 C_C ++ \ C \ Algorithm \ BTS \ Debug \ BST.exe:致命的   错误LNK1120:4个未解决的外部

0 个答案:

没有答案