c++ - C++ 未解析的外部符号
问题描述
我尝试使用构造函数将类对象创建到另一个类中,但出现“无法解析的外部符号”错误。我研究示例代码,但在我的代码中找不到任何错误。
链表.h
#pragma once
#include <cstdint>
#include <list>
#include <iterator>
using namespace std;
template <class T> class LinkedList
{
public:
LinkedList();
LinkedList(int Size);
list <T> data;
int size;
LinkedList* next;
};
链表.cpp
#include "LinkedList.h"
template <class T>
LinkedList <T> ::LinkedList() {
size = 0;
next = NULL;
}
template <class T>
LinkedList <T> ::LinkedList(int Size) {
size = Size;
next = NULL;
}
Cotp_connection.h
#pragma once
#include "connect_tcp.h"
#include "LinkedList.h"
class Cotp_connection {
public:
Cotp_connection();
Cotp_connection(int size);
};
Cotp_connection.cpp
#include "Cotp_connection.h"
Cotp_connection::Cotp_connection() {
LinkedList <uint8_t> list;
}
Cotp_connection::Cotp_connection(int size) {
LinkedList <uint8_t> list(size);
}
LNK2019 未解析的外部符号“public: __thiscall LinkedList::LinkedList(void)” (??0?$LinkedList@E@@QAE@XZ) 在函数“public: __thiscall Cotp_connection::Cotp_connection(void)” (??0Cotp_connection @@QAE@XZ) kkkkk_v2
编辑:如果我以这种方式编辑我的代码,它可以工作。Okey,但为什么它现在可以工作,但以前不行?
Cotp_connection.cpp
Cotp_connection::Cotp_connection() {
LinkedList <uint8_t> list();
}
Cotp_connection::Cotp_connection(int size) {
LinkedList <uint8_t> list((size));
}
链表.h
#pragma once
#include <cstdint>
#include <list>
#include <iterator>
using namespace std;
template <class T> class LinkedList
{
public:
LinkedList();
LinkedList(int Size) :size(Size),next(NULL) {};
list <T> data;
int size;
LinkedList* next;
};
解决方案
推荐阅读
- mosel - XPRESS Mosel - 错误的逻辑运算符
- docker - 构建 DockerFile 时出现此错误
- javascript - jquery__WEBPACK_IMPORTED_MODULE_3___default(...)(...).mCustomScrollbar 不是函数
- python - CSS 没有在 Django 中加载
- unity3d - 对人形角色使用对撞机的正确方法:Unity
- angular - 多个 p 树节点中的 PrimeNg 下拉菜单:区分所选选项
- python - 多线程和单线程在 Python 中提供相同的性能
- python - Python matplotlib 子图:并排放置水平条形图和轴上不需要的数字标签
- python - If then else Python
- c# - 以编程方式制作的按钮无法更改悬停颜色 c# winforms