该程序应该通过只使用一个变量和任意数量的栈来检查字符串是否是回文。它给我提供了一些与重载函数有关的错误消息,但是我看不到它超载的地方。还是我宣布堆栈错了?我在他们提到的代码行之后的错误消息中发表了评论。谢谢!重载函数错误消息
int main()
{
stack <char> stackA;
stack <char> stackB;
stack <char> stackC;
char avariable;
cout << "Enter a string: ";
avariable = cin.get();
while(avariable != '\n')
{
if(avariable != ' ')
{
stackA.push(avariable);
stackB.push(avariable);
avariable = cin.get();
}}
stackC.push('$');
while(!stackB.empty())
{
avariable = stackB.top; //error, cannot resolve overloaded function 'top' based on conversion to type 'char'
stackC.push(avariable);
stackB.pop; //statement cannot resolve address of overloaded function
}
avariable = '$';
stackC.push('$');
while(!stackA.empty())
{
if(avariable == stackC.top) //invalid operands of type 'char' and <unresolved overloaded function type>' to binary 'operator=='
{
avariable = stackA.top; //cannot resolve overloaded function 'top' based on conversion to type 'char'
stackA.pop; //cannot resolve address of overloaded function
stackC.pop; //cannot resolve address of overloaded function
}
else
{
cout << "The string of characters entered is not a palindrome." << endl;
}
}
if (stackC.top == '$') //invalid operands of type 'char' and <unresolved overloaded function type>' to binary 'operator=='
{
cout <<"The string of characters entered is a palindrome." << endl;
}
}
为什么你说为每个实例使用std ::更好?我被一位教授告诉了相反的情况,尽管我不记得他解释了它的好处。 – Neko
@Neko,[Read here](http://stackoverflow.com/q/1452721/493122)。 – Shoe
谢谢!我想我应该在查问之前查看它。 – Neko