How do I use "this" in a member function?

Posted by Peter Stewart on Stack Overflow See other posts from Stack Overflow or by Peter Stewart
Published on 2010-05-03T23:39:23Z Indexed on 2010/05/03 23:48 UTC
Read the original article Hit count: 223

Filed under:
|

I've written a member function of class Node to read a tree of Nodes in postfix order.

It will be called by the Node instance which is the root node of the tree.

So: N.postfix();

these appear to be illeagal:

*this->left.postfix();
*this->right.postfix();

What is the proper way to do this?

class Node
{
public:
    const char *cargo; 
    int depth; 
    Node *left; 
    Node *right

void Node::postfix()
{
    if (this==__nullptr)
    {
        return;
    }
    else
    {
        *this->left.postfix();
        *this->right.postfix();
        out<<*this->cargo<<"\n";
        return;
    }
};

© Stack Overflow or respective owner

Related posts about c++

Related posts about beginner