mardi 24 décembre 2019

Invalid use of non-static data member when setting begin iterator

I'm writing a tree that follows this header:

class TreeLetters {
private:
    Letter* root;

public:
    // ...

    Letter* Root () const;

    class iterator {
    private:
        Letter* it;

    public:
        iterator ();
        iterator (Letter* letter);
        iterator (const iterator & other);

        iterator begin ();
        iterator end   ();

        // ...
    };
};

As simple as it is, I'm getting an error with the iterator's begin() method, which is as follows:

TreeLetters::iterator TreeLetters::iterator :: begin () {
    return iterator(root); // invalid use of non-static data member 'TreeLetters:root'
}

I've been reading some old questions and the only solution that has at least swept the problem under the rug for me is making the root static, which creates the greater problem of not being able to have more than one tree.

I've tried making the root protected and adding a friend class TreeLetters to the private members of the iterator, but nothing has worked. I'm also working with C++11.

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire