帮忙找下错误,不知道哪里错了

xiaowenmanbu 2008-03-27 03:41:34

#include <assert.h>
#include <iostream>
#include "stack.h"

using namespace std;

const int stackIncreament = 20;//栈溢出时扩展空间的增量

template<class T>
class SeqStack: public Stack<T> //顺序表的类定义
{
public:
SeqStack(int sz = 50); //建立一个空栈
~SeqStack() //析构函数
{
delete [] elements;
}
void Push(const T& x);
//如果IsFull(),则溢出处理,否则把x插入到栈的栈顶。
bool Pop(T& x);
//如果IsEmpty(),则不执行退栈,返回false;否则退掉栈顶的元素,返回true,
//退出的元素值通过引用型参数x返回。
bool getTop(T& x) const;
//如果IsEmpty(),返回false;否则返回true,通过引用型参数x得到栈顶元素的值。
bool IsEmpty() const
{
return (top == -1) ? true:false;
}
//如果栈中元素个数等于0,则返回true,否则返回false
bool IsFull() const
{
return (top == -1) ? true : false;
}
//如果栈中元素个数等于maxSize,则返回true,否则返回false。
int getSize() const //函数返回栈中元素个数
{
return top+1;
}
void MakeEmpty() //清空栈的内容
{
top = -1;
}
friend ostream& operator<<(ostream& os,SeqStack<T>& s);
//输出占中元素的重载操作<<
private:
T *elements;
int top;
int maxSize;
void overflowProcess();
void stackFull();
};


template<class T>
SeqStack<T>::SeqStack(int sz)//;top(-1),maxSize(sz)
{
//建立一个最大尺寸为sz的空栈,若分配不成功则错误处理
top = -1;
maxSize = sz;
elements = new T[maxSize];
assert(elements != NULL);
}

template<class T>
void SeqStack<T>::overflowProcess()
{
T * newArray = new T[maxSize + stackIncreament];
if(newArray = NULL)
{
cerr << "存储分配失败!" << endl;
exit(1);
}
for(int i = 0;i <= top; i++)
newArray[i] = elements[i];
maxSize = maxSize + stackIncreament;
delete [] elements;
elements = newArray;
}

template<class T>
void SeqStack<T>::Push(const T &x)
{
if(IsFull() == true)
stackFull();
// overflowProcess();
elements[++top] = x;
}

template<class T>
bool SeqStack<T>::Pop(T& x)
{
if(IsEmpty() == true)
return false;
x = elements[top--];
return true;
}

template<class T>
bool SeqStack<T>::getTop(T& x) const
{
if(IsEmpty() == true)
return false;
x = elements[top];
return true;
}

template<class T>
ostream& operator<<(ostream& os,SeqStack<T>& s)
{
os << "top = " << s.top << endl;
for( int i = 0; i <= s.top; i++)
os << i << ":" << s.elements[i] << endl;
return os;
}

template<class T>
void SeqStack<T>::stackFull()
{
T * newArray = new T[3 * maxSize];
if(newArray = NULL)
{
cerr << "存储分配失败!" << endl;
exit(1);
}
for(int i = 0;i <= top; i++)
newArray[i] = elements[i];
maxSize = 3 * maxSize;
delete [] elements;
elements = newArray;
}
...全文
130 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
txwcan999 2008-03-28
  • 打赏
  • 举报
回复
operator << 错误

看看作用域
Chappell 2008-03-27
  • 打赏
  • 举报
回复
#include "stack.h" -------> #include <stack>
public Stack <T> //顺序表的类定义 -------> public stack <T> //顺序表的类定义

xiaowenmanbu 2008-03-27
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include "SeqStack.h"


int _tmain(int argc, _TCHAR* argv[])
{
SeqStack<int> s;
s.Push( 3 );
cout << s;
return 0;
}
csdn5211 2008-03-27
  • 打赏
  • 举报
回复
看看你的main那个文件是什么样,贴上来。
xiaowenmanbu 2008-03-27
  • 打赏
  • 举报
回复
>DS_3_9.obj : error LNK2019: 无法解析的外部符号 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class SeqStack<int> &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@AAV?$SeqStack@H@@@Z),该符号在函数 _wmain 中被引用
1>DS_3_9.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall Stack<int>::getTop(int &)const " (?getTop@?$Stack@H@@UBE_NAAH@Z)
1>G:\数据结构\DS_3_9\Debug\DS_3_9.exe : fatal error LNK1120: 2 个无法解析的外部命令
xiaowenmanbu 2008-03-27
  • 打赏
  • 举报
回复
>DS_3_9.obj : error LNK2019: 无法解析的外部符号 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class SeqStack<int> &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@AAV?$SeqStack@H@@@Z),该符号在函数 _wmain 中被引用
1>DS_3_9.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall Stack<int>::getTop(int &)const " (?getTop@?$Stack@H@@UBE_NAAH@Z)
1>G:\数据结构\DS_3_9\Debug\DS_3_9.exe : fatal error LNK1120: 2 个无法解析的外部命令

64,634

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧