unresolved externals

mymyway mymyway 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
哪里有错误呢?怎么老是通不过?


///头文件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;
}


...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
mymyway
C++ 语言 65,214 成员 250,514 内容