c++ - LNK2019未解析的外部符号。创建二叉树

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?

(34个答案)


7年前关闭。




我创建了链接列表,它没有问题并且可以运行。另外,我必须包括二叉树。它给我这个错误
1> Generating Code... 1> Skipping... (no relevant changes detected) 1> main.cpp 1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall SDI::BinaryTree::insert(int)" (?insert@BinaryTree@SDI@@QAEHH@Z) referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall SDI::BinaryTree::preOrder(void)" (?preOrder@BinaryTree@SDI@@QAEHXZ) referenced in function _main 1>C:\Users\Muugii\Documents\Visual Studio 2013\LinkedList\Debug\LinkedList.exe : fatal error LNK1120: 2 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
BinaryTree.h

ifndef SDI_BINARYTREE

define SDI_BINARYTREE



包括
namespace SDI
{
    class BinaryTree
    {
        class BTNode
        {
        public:
            int data;
            BTNode *left;
            BTNode *right;
        };

    public:
        BinaryTree();
        ~BinaryTree();

        int insert(const int value);
        int preOrder() const;
        int clearTree();

    private:

        BTNode *headPtr;

        int insert(const int value, BTNode *leaf);
        int clearTree(BTNode *leaf) const;
        int preOrder(BTNode *leaf) const;

    };
};

#endif

BinaryTree.cpp
#include"BinaryTree.h"
#include <iostream>

using namespace std;


SDI::BinaryTree::BinaryTree()
{
    headPtr = nullptr;
}

SDI::BinaryTree::~BinaryTree()
{
    //clearTree(headPtr);
}

int SDI::BinaryTree::insert(const int value, BTNode *leaf)
{
    if (value < leaf->data)
    {
        if (leaf->left != nullptr)
        {
            insert(value, leaf->left);
        }
        else
        {
            leaf->left = new BTNode;
            leaf->left->data = value;
            leaf->left->left = nullptr;
            leaf->left->right = nullptr;
        }
    }
    else if (value >= leaf->data)
    {
        if (leaf->right != nullptr)
        {
            insert(value, leaf->right);
        }
        else
        {
            leaf->right = new BTNode;
            leaf->right->data = value;
            leaf->right->left = nullptr;
            leaf->right->right = nullptr;
        }
    }
    return 1;
}

Main.cpp
#include <string>
#include <iostream>
#include "Linkedlist.h"
#include "BinaryTree.h"

using namespace std;

int main( int argc, const char *argv[])
{

    SDI::LinkedList myList;
    //SDI::BinaryTree myTree;
    int inp;

....

if (inp2 == 'a')
                {
                    int num;

                        cout << "\nPlease enter a value to add: ";
                        cin >> num;
                        myTree.insert(num);
                        cout << "\n\t\tValue has been successfully saved\n\n\n";


                }

我尝试过在线查找,找不到任何内容。这将是极大的帮助。

最佳答案

如我所见,您具有名称插入的两个功能。还有第一个

int insert(const int value);

仅声明但未定义。

https://stackoverflow.com/questions/21080721/

上一篇:c++ - 我的程序未发现struct中的功能

下一篇:delphi - delphi编译错误 "[DCC Error] ProjectName.dpr([number]): E1026 File not found: ' FileName.dn'

相关文章:

c++ - 计算圆的顶点

c++ - OpenCV + 实感 : Visual Studio Link 2019 error

java - 高效的 hashCode() 实现

c - gmp 奇怪的行为不允许我编译新项目

c++ - 有没有办法告诉 gcc 在报告错误时不要替换 typedef 名称和默认参数?

c++ - 为什么 value_type 函数在 SGI STL 中返回一个指针

c++ - 需要澄清 boost::optional 类型

java - 如何在有向图中从特定顶点执行 BFS 或 DFS,其中某些顶点的出度为 0?

javascript - 暴力破解对数

c# - '操作在检查模式下编译时溢出'错误

相关文章:

c++ - '' *2之前的解析错误

c++ - 我的程序未发现struct中的功能

c# - 如何正确地将 Dictionary,Object

python - 使用 MinGW+GCC 编译 SciPy 时编译器失败

php - PHP中 undefined index 错误

c++ - 在此范围C++中未声明错误 'menu'

.net - 使用xmlrpc和vb.net在wordpress中发布错误

c++ - 代码编译错误

c++ - header 多重重新定义

c# - C#中的编译时错误