unresolved externals
哪里有错误呢?怎么老是通不过?
///头文件stackhpp.h
template <class Type>
class Stack{
public:
Stack(int s);
~Stack();
void push(Type &item);
void pop();
Type top();
bool empty() const;
bool isfull() const;
private:
const int maxstack;
int count;
Type* stack;
};
////实现文件stackhpp.cpp
#include "stdafx.h"
#include "stackhpp.h"
#include<iostream>
#include"process.h"
using namespace std;
template <class Type>
Stack<Type>::Stack(int s)
{
maxstack=s;
Type*element=new Type[maxstack];
count=0;
}
template <class Type>
Stack<Type>::~Stack()
{
delete []element;
}
template <class Type>
void Stack<Type>::push(Type &item)
{
if(count>=maxstack){
cout<<"can not push.";
exit(1);
}
else
element[count++]=item;
}
template <class Type>
void Stack<Type>::pop()
{
if(count==0)
cout<<"can not pop.";
else
count--;
}
template <class Type>
Type Stack<Type>::top()
{
if(count==0)
cout<<"no elemenet.";
else
return element[count-1];
}
template <class Type>
bool Stack<Type>::empty() const
{
if(count==0)
return true;
else
return false;
}
template <class Type>
bool Stack<Type>::isfull() const
{
if(count==maxstack)
return true;
else
return false;
}
////主函数
// stack22.cpp : 定义控制台应用程序的入口点。
//
//#include "stdafx.h"
#include "stackhpp.h"
int main()
{
Stack <int> aaa(5);
return 0;
}