[英]Error LNK2019: unresolved external symbol error message when compiling program using classes
I just installed VS 2013 this week (Have been using 2012 version before). 我本周刚刚安装了VS 2013(以前一直使用2012版本)。 I got an error in this first program I am trying to do using classes. 我尝试使用类在第一个程序中遇到错误。 I tried to read other threads with similar error but none of the answers have worked for me so far. 我尝试读取具有类似错误的其他线程,但到目前为止,没有任何答案对我有用。 This is supposed to be a program that is based on a stack. 这应该是一个基于堆栈的程序。
Error 错误
1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1> Source.cpp
1> Generating Code...
1> Compiling...
1> Stackt.cpp
1> Generating Code...
1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall Stackt<char>::Stackt<char>(int)" (??0?$Stackt@D@@QAE@H@Z) referenced in function _main
1>C:\Users\Documents\Visual Studio 2013\Projects\Project1\Debug\Project1.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
stackt.h 堆积量
#ifndef STACKT_H
#define STACKT_H
template <class Type>
class Stackt
{
public:
Stackt(int n = 128);
private:
Type *stack;
int top, max;
};
#endif
stack.cpp stack.cpp
#include "Stackt.h"
template <class Type>
Stackt<Type>::Stackt(int n)
{
max = n;
stack = new Type[max];
top = -1;
}
source.cpp source.cpp
#include <iostream>
#include "Stackt.h"
void main()
{
Stackt<char> s1;
}
Thanks 谢谢
Template implementations must be available to the compiler at compile time. 模板实现必须在编译时可供编译器使用。 You must define template<typename T> Stackt<T>::Stackt(int n)
in the header file. 您必须在头文件中定义template<typename T> Stackt<T>::Stackt(int n)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.