【发布时间】:2011-02-15 14:12:43
【问题描述】:
感谢我在这篇文章中得到的帮助:
How do I use "this" in a member function?
我有一个简洁的递归函数以后缀顺序遍历树:
void Node::postfix()
{
if (left != __nullptr) { left->postfix(); }
if (right != __nullptr) { right->postfix(); }
cout<<cargo<<"\n";
return;
};
现在我需要评估返回的值和运算符。我的问题是如何检索
他们。我尝试了 std::stack:
#include <stack>
stack <char*> s;
void Node::postfix()
{
if (left != __nullptr) { left->postfix(); }
if (right != __nullptr) { right->postfix(); }
s.push(cargo);
return;
};
但是当我尝试在 main() 中访问它时
while (!s.empty())
{
cout<<s.top<<"\n";
s.pop;
}
我得到了错误:
'std::stack<_ty>::top': 函数调用缺少参数列表;使用 '&std::stack<_ty>::top' 创建
指向成员的指针'
我被困住了。
另一个问题很快就会跟进。
【问题讨论】: