错误LNK2019致命错误 C
ERROR LNK2019 FATAL ERROR C
可能的重复项:
为什么模板只能在头文件中实现?
具有简单模板类的"未定义的符号"链接器错误
队列.h
#include<iostream>
using namespace std;
template <class t>
class queue {
public:
queue(int=10);
void push(t&);
void pop();
bool empty();
private:
int maxqueue;
int emptyqueue;
int top;
t* item;
};
队列.cpp
#include<iostream>
#include"queue.h"
using namespace std;
template <class t>
queue<t>::queue(int a){
maxqueue=a>0?a:10;
emptyqueue=-1;
item=new t[a];
top=0;
}
template <class t>
void queue<t>::push(t °er){
if(empty()){
item[top]=deger;
top++;
}
else
cout<<"queue is full";
}
template<class t>
void queue<t>::pop(){
for(int i=0;i<maxqueue-1;i++){
item[i]=item[i+1];
}
top--;
if(top=emptyqueue)
cout<<"queue is empty";
}
template<class t>
bool queue<t>::empty(){
if((top+1)==maxqueue)
return false
else
return true
}
主.cpp
#include<iostream>
#include<conio.h>
#include"queue.h"
using namespace std;
void main(){
queue<int>intqueue(5);
int x=4;
intqueue.push(x);
getch();
}
我已经使用模板创建了队列。编译器给出了此错误。我无法解决这个问题。
1>main.obj :错误LNK2019:函数_main中引用的未解析的外部符号"public: void __thiscall queue::p ush(int)" (?push@?$queue@H@@QAEXH@Z) 1>main.obj : 错误 LNK2019: 未解析的外部符号 "public: __thiscall queue::queue(int)" (??0?$queue@H@@QAE@H@Z) 在函数 _main 中引用 1>c:\users\pc\documents\visual Studio 2010\Projects\lab10\Debug\lab10.exe:致命错误LNK1120:2 个未解析的外部
编辑:解决方案在这里给出。
将所有与模板相关的队列实现放在头文件中。就像:为什么模板只能在头文件中实现?
模板类不能分为 .cpp 和 .h 文件,因为编译器需要实现的副本才能从模板生成所需的类。
您需要将队列的内容.cpp移动到队列中.cpp
相关文章:
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- 如何修复valgrind启动时的致命错误(与libc6-dbg和libc6-dbg:i386连接)
- 在Raspbian上编译pybind11测试用例时出现致命错误
- 致命错误:特征/密集:VSC 中没有此类文件或目录
- v8::HandleScope::CreateHandle() # 中的致命错误无法在没有 HandleScope 的情
- Visual Studio中的wxwidgets应用程序给出错误"LNK2019 unresolved external symbol"
- macOS 致命错误:sys/_types/_int8_t.h:没有此类文件或目录 #include < sys/_types/_int8_t.h>
- /usr/include/c++/7/cstdlib:75:15:致命错误:stdlib.h:没有这样的文件或目录 #i
- 代码::块C++使用 MacOS 编译 Mojave : 致命错误: sys/cdefs.h: 没有这样的文件或目录
- 致命错误:找不到'boost/uuid/uuid.hpp'文件
- 构建 Tensorflow 调试时出现错误LNK2019
- 致命错误 C1001 :vs2017 15.8.4 的内部错误(编译器文件"msc1.cpp",第
- 链接:致命错误LNK1104:无法打开文件"python37_d.lib"
- 造成致命错误:boost/fusion/iterator/equal_to.hpp 没有这样的文件或目录
- 错误LNK2019致命错误 C
- 致命错误LNK1120:1 个未解析的外部 & 错误 LNK2019:函数___tmainCRTStartup中引用_main未解析的外部符号
- LNK2019:函数"函数"中'symbol'引用未解析的外部符号;致命错误 LNK1120:1 未解析的外部
- 程序应该运行…致命错误LNK1120和错误LNK2019
- 错误 LNK2019 和 致命错误 LNK1120:2 个未解析的外部