感謝我在這個崗位得到的幫助麻煩:我在使用的std ::堆棧以遞歸函數檢索值
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 ::堆棧:
#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 ::堆棧< _Ty> :: top':函數調用缺少參數列表;使用 '&的std ::堆棧< _Ty> ::頂' 創建
一個成員指針」
我卡住了。
很快就會有另一個問題。
該死!就如此容易。感謝所有的答案。 – 2010-05-04 17:54:35