I am having trouble using std :: stack to extract values from a recursive function
Thanks for the help I got in this post:
How do I use "his" in a member function?
I have a nice, concise recursive function to traverse a tree in postfix order:
void Node::postfix()
{
if (left != __nullptr) { left->postfix(); }
if (right != __nullptr) { right->postfix(); }
cout<<cargo<<"\n";
return;
};
Now I need to evaluate values and operators as they are returned. My problem is how to get
them. I tried std :: stack:
#include <stack>
stack <char*> s;
void Node::postfix()
{
if (left != __nullptr) { left->postfix(); }
if (right != __nullptr) { right->postfix(); }
s.push(cargo);
return;
};
but when i tried to access it in main ()
while (!s.empty())
{
cout<<s.top<<"\n";
s.pop;
}
I got the error:
'std :: stack <_Ty> :: top': call list of missing function arguments; use '& std :: stack <_Ty> :: top' to create
element pointer
I am stuck.
One more question that needs to be completed in the near future.
a source to share
They are member functions:
s.top()
s.pop()
^ need parentheses to call a function
That's what the error means when it says "list of missing function arguments". The argument list (which in this case is empty, since the function takes no parameters) and the parentheses are missing.
a source to share