LNK2019未解析的外部符号.创建二叉树
LNK2019 unresolved external symbol. Creating Binary Tree
我创建了链表,它没有问题并运行。另外,我必须包括二叉树。它给了我这个错误
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:UsersMuugiiDocumentsVisual Studio 2013LinkedListDebugLinkedList.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
二进制树.h
IFNDEF SDI_BINARYTREE
定义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
二进制树.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;
}
主.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 << "nttValue has been successfully savednnn";
}
我试过在网上查找,找不到。这将是很大的帮助。
如我所见,您有两个带有名称插入的函数。而第一个
int insert(const int value);
仅声明但未定义。
您不清楚错误消息的哪一部分?它清楚地表明您尚未实现两种方法:
int SDI::BinaryTree::insert(const int value) {
return 0; // the implementation probably needs some patching up
}
int SDI::BinaryTree::preOrder() const {
return 0; // as does this one
}
- 如何防止 CMake 在构建时(而不是在安装时)为共享库创建符号链接?
- Rcpp 包创建符号未找到错误
- 创建具有未定义溢出的无符号 int
- 创建类时已定义的未解析外部符号
- 使用JNI和OPENCV创建的LIB的未定义符号
- bad_alloc::'标量删除析构函数'(无符号整数)当我尝试创建矢量 470MB 大小时
- 在创建共享对象时,不能使用针对未定义符号的重定位R_X86_64_PC32;使用-fPIC重新编译
- g++ - 虚拟方法在生成的二进制中创建符号,我无法隐藏
- 我可以在libleveldb.a中找到符号,但是当我创建共享库时,找不到相同的符号。
- 创建指向未符号char []的指针,然后将其传递给SF :: Soundbuffer :: LoadFromememor
- 使用C constexpr可以创建符号重复
- 创建集合成员(C )成员的每个置换和符号变化的集合
- 为什么不在此静态库中创建多个定义的符号?
- 富文本编辑器--创建和维护项目符号列表时的问题
- 通过使用新操作员创建对象会导致未解决的外部符号错误C FTGL
- LNK2019未解析的外部符号.创建二叉树
- g++正在创建静态库:无法读取符号.存档没有索引
- 尝试创建一个 3D 矢量,该矢量将保留指向指向无符号字符的指针的指针
- 严格的混叠警告,创建对无符号字符数组 + 偏移量的uint32_t引用
- Ctypes 在使用 CMake 创建的共享库中找不到符号