还有一点小错误!

840206 2004-08-30 12:24:42
要求:
1:利用链表模拟栈
2:演示栈的基本操作
3:栈采用模板,栈的节点需要是一个描述学生记录的类对象
template<class T>
class genabstractstack
{
protected:
unsigned height;
public:
bool isempty()
{
return(height==0)? true:false;
}
virtual void push(T &)=0;
virtual bool pop(T &)=0;
virtual void clear()=0;
};
template<class T>
struct genstackrec
{
T nodedata;
genstackrec * next;
};
template<class T>
class genstack:public genabstractstack<T>
{ protected:
bool allocateerror;
genstackrec<T> * top;
genstack & copy(genstack &);
public:
genstack();
genstack(genstack & g)
{top=NULL;copy(g);}
~genstack()
{clear();}
bool getallocateerror()
{return allocateerror;}
virtual void clear();
virtual void push(T & x);
virtual bool pop(T & x);

genstack & operator=(genstack & g)
{copy(g);return * this;}
};
template<class T>
genstack<T>::genstack()
{
height=0;
allocateerror=false;
top=NULL;
}
template<class T>
genstack<T>&genstack<T>::copy(genstack<T>&g)
{
genstackrec<T> *p,*q,*r;
if(top) clear();
height=g.height;
allocateerror=false;
top=NULL;
if(! g.top)
return * this;
top=new genstackrec<T>;
if(! top)
{
allocateerror=true;
return * this;
}
top->next=NULL;
top->nodedata=g.top->nodedata;
q=g.top->next;
p=top;
while(q)
{
r=new genstackrec<T>;
if(! r)
{allocateerror=true;
return * this;
}

r->nodedata=q->nodedata;
r->next=NULL;
p->next=r;
p=p->next;
q=q->next;
}
return * this;
}
template<class T>
void genstack<T>::clear()
{
T x;
while(pop(x));
}
template<class T>
void genstack<T>::push(T & x)
{
genstackrec<T> * p;
allocateerror=false;
if(top)
{
p=new genstackrec<T>;
if(!p)
{
allocateerror=true;
return;
}
p->nodedata=x;
p->next=top;
top=p;
}
else
{
top=new genstackrec<T>;
if(!top)
{
allocateerror=true;
return;
}
top->nodedata=x;
top->next=NULL;

}
height++;
}
template<class T>
bool genstack<T>::pop(T & x)
{
genstackrec<T> * p;
if(height)
{
x=top->nodedata;
p=top;
top=top->next;
delete p;
height--;
return true;
}
return false;
}

#include<string.h>
#include<stdio.h>
#include<dos.h>
#include<iostream.h>
#include<conio.h>
#include "StdAfx.h"
class student
{
public:
char name[80];
int age;
float mark_average;
char sex[8];
void scanf(char *name,int age,float mark_average,char *sex);
void print();

};
void student::scanf(char *name,int age,float mark_average,char *sex)
{
strcpy(student::name,name);
student::age=age;
student::mark_average=mark_average;
strcpy(student::sex,sex);
}

void viewstack(genstack <student> &stack)
{
student p;
int i=1;
genstack <student> stackcopy(stack);
while(stackcopy.pop(p))
{

printf("%2d:",i++);
p.print();

}
}
main()
{ student p;
genstack<student>stack;
int i;

for(i=0;i<4;i++)
{
//cin>>p;
scanf("请输入学生的数据:");
stack.push(p);
}
while(stack.pop(p))
{
viewstack(stack);

}
stack.clear();
return 1;
}
--------------------Configuration: ll - Win32 Debug--------------------
Linking...
ll.obj : error LNK2001: unresolved external symbol "public: void __thiscall student::print(void)" (?print@student@@QAEXXZ)
Debug/ll.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

ll.exe - 2 error(s), 0 warning(s)

...全文
88 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
goodluckyxl 2004-08-30
  • 打赏
  • 举报
回复
2001一般是找不到函数体
很可能就象你包括了头文件但是没有将连接库add进去
就会出这样的错
没有定义函数体,怎么可能不报连接错
goodluckyxl 2004-08-30
  • 打赏
  • 举报
回复
你是真的没有print的函数体
void print() {}; 这样定义旧没有错误了
Andy84920 2004-08-30
  • 打赏
  • 举报
回复
链接错误,你的问题我没办法编译呀,我没有VC环境,GCC下没有conio.h的..所以帮不了..
840206 2004-08-30
  • 打赏
  • 举报
回复
这个错误在哪我都不知道啊
840206 2004-08-30
  • 打赏
  • 举报
回复
我用的是VC啊
Andy84920 2004-08-30
  • 打赏
  • 举报
回复
你可能是用的VC吧,VC库里有conio.h吗?我不太清楚.反正只知道TC里有这个东西.
Andy84920 2004-08-30
  • 打赏
  • 举报
回复
居然有conio.h,你用的什么编译器呀?
goodluckyxl 2004-08-30
  • 打赏
  • 举报
回复
是不是没有定义函数体
student::print(void)的函数体
840206 2004-08-30
  • 打赏
  • 举报
回复
快来人啊!!
Andy84920 2004-08-30
  • 打赏
  • 举报
回复
你试一下不就得了?
840206 2004-08-30
  • 打赏
  • 举报
回复
是这的错误吗?
有没有有高手帮调试一下啊!!!!
谢谢了 !
sharkhuang 2004-08-30
  • 打赏
  • 举报
回复
print()声明了没有实现啊.

64,654

社区成员

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

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