对于我的学校作业,我需要制作一个使用链表制作堆栈的程序。我不断收到链接器错误(特别是:error LNK2019: unresolved external symbol "public: __thiscall Stack::Stack(void)" (??0?$Stack@H@@QAE@XZ) referenced in function _main 1>C: \Users\devon.taylor\Desktop\New folder\Debug\PA3.exe : 致命错误 LNK1120: 1 unresolved externals)
这是我的代码:
标题:
template <class T>
class Stack
{
public:
Stack();
Stack(T data);
~Stack();
void push(T data);
T pop();
void display();
bool isEmpty();
bool isExist(T searchKey);
private:
Stack<T> *top;
Stack<T> *next;
T mData;
};
职能:
#include "stack.h"
#include <iostream>
using namespace std;
template <class T>
Stack<T>::Stack()
{
top=NULL;
}
template <class T>
Stack<T>::Stack(T data)
{
mData = data;
pNext = NULL;
}
template <class T>
Stack<T>::~Stack()
{
}
template <class T>
void Stack<T>::push(T data)
{
Stack *ptr;
ptr=new Stack<T>;
ptr->mData=data;
ptr->next=NULL;
if(top!=NULL)
{
ptr->next=top;
}
top=ptr;
cout<<"\nNew item inserted to the stack";
}
template <class T>
T Stack<T>::pop()
{
}
template <class T>
void Stack<T>::display()
{
}
主功能:
#include <iostream>
#include "stack.h"
using namespace std;
void main ()
{
Stack<int>* stack;
stack = new Stack<int>;
//stack->push(19);
system("pause");
}