C++面向对象程序设计栈的实现题目小问题求解答

#include"Stack.h"
int main()
{Stack<char>charStack;
char c='a';
cout<<"Pushing elements onto charStack"<<endl;
while(charStack.push(c))
{cout<<c<<" ";
c+=1;
}
cout<<endl<<"Stack is full. Cannot push "<<c<<endl<<"Poping elements from charStack"<<endl;
while(charStack.pop(c)) <- 错误信息所指处
cout<< c <<" ";
cout<<endl<<"Stack is empty. Cannot pop"<<endl;
Stack<double>doubleStack(5);
double f=1.1;
cout<<"Pushing elements onto doubleStack "<<endl;
while(doubleStack.push(f))
{cout<<f<<" ";
f+=1.1;
}
cout<<endl<<"Stack is full. Cannot push "<<f<<endl<<"Poping elements from doubleStack"<<endl;
while(doubleStack.pop(f))
cout<<f<<" ";
cout<<endl<<"Stack is empty. Cannot pop "<<endl;
Stack<int>intStack;
int i=1;
cout<<"Pushing elements onto intStack "<<endl;
while(intStack.push(i))
{cout<<i<<" ";
i+=1;
}
cout<<endl<<"Stack is full. Cannot push"<<i<<endl<<"Poping elements from intStack"<<endl;
while(intStack .pop(i))
cout<<i<<" ";
cout<<endl<<"Stack is empty. Cannot pop"<<endl;
return 0;
}
错误信息:
error C2039: 'pop' : is not a member of 'Stack<char>'
fatal error C1903: unable to recover from previous error(s); stopping compilation

是说pop不是模板类Stack的成员函数。
这个应该是树上的例子吧。
你核对下,是不是敲错了。
你贴的代码不全。没办法帮你改正。
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答