📄 subject_35273.htm
字号:
<p>
序号:35273 发表者:flyingdonkey 发表日期:2003-04-05 10:22:25
<br>主题:关于模板
<br>内容:我定义了一个栈的模板<BR>用的是visual c++ 6。0的编译器<BR>可是,在左边的work space里边<BR>的类下边显示不出来,类里边的成员函数<BR>这是为什么呢??<BR>#include <iostream.h><BR><BR>#include <stdlib.h><BR><BR>#include <stdio.h><BR><BR>#define Maxsize 20<BR><BR>template <class Type><BR>class Mystack<BR>{<BR> public:<BR> Mystack();<BR> void Push(Type);<BR> bool Pop();<BR> bool Isempty();<BR> bool Isfull();<BR> Type Gettop();<BR> private:<BR> Type *top;<BR> Type *base;<BR>};<BR><BR>template <class Type> <BR>Mystack<Type>::Mystack()<BR>{<BR> base=new Type[Maxsize+1];<BR> top=base;<BR>}<BR><BR>template <class Type> void Mystack <Type>::Push(Type x)<BR>{<BR> if(!Isfull())<BR> {<BR> top++;<BR> *top=x;<BR> }<BR> else <BR> {<BR> cout<<"the stack is full!\n"<<flush;<BR> exit(0);<BR> <BR> } <BR>}<BR><BR>template <class Type> bool Mystack<Type>::Pop()<BR>{<BR> if(!Isempty())<BR> {<BR> top--;<BR> return 1;<BR> }<BR> else <BR> {<BR> cout<<"the stack is empty!";<BR> return 0;<BR> <BR> }<BR>}<BR><BR>template <class Type> bool Mystack<Type>::Isempty()<BR>{<BR> return top==base;<BR>}<BR><BR>template <class Type> bool Mystack<Type>::Isfull()<BR>{<BR> return (top-base)==Maxsize;<BR>}<BR><BR><BR>template <class Type> Type Mystack<Type>::Gettop()<BR>{<BR> return *top;<BR>}
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:xiongli 回复日期:2003-04-05 10:49:53
<br>内容:正常
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -