W
Wolfgang Jeltsch
Hello,
I want to write a list class with an iterator class as an inner class. The
iterator class must have access to certain private members of the list
class in order to do its job. Here is a reduced code example:
class List {
private:
void *rootNode;
class Iterator {
private:
void *currentNode;
public:
Iterator( List &listRef ) : currentNode( listRef.rootNode ) {}
};
};
I wouldn't think that this is a problem. The inner class is like a member of
the outer class. Other members of the outer class (e.g., member functions)
also have access to private members of the outer class. But surprisingly,
g++ 2.95.4 complains about the list class members being private.
The problem now is not only that I don't understand and don't want this
behaviour; the problem is also that I cannot imagine a proper workaround.
I'm happy for any comments clarifying this situation.
Wolfgang
I want to write a list class with an iterator class as an inner class. The
iterator class must have access to certain private members of the list
class in order to do its job. Here is a reduced code example:
class List {
private:
void *rootNode;
class Iterator {
private:
void *currentNode;
public:
Iterator( List &listRef ) : currentNode( listRef.rootNode ) {}
};
};
I wouldn't think that this is a problem. The inner class is like a member of
the outer class. Other members of the outer class (e.g., member functions)
also have access to private members of the outer class. But surprisingly,
g++ 2.95.4 complains about the list class members being private.
The problem now is not only that I don't understand and don't want this
behaviour; the problem is also that I cannot imagine a proper workaround.
I'm happy for any comments clarifying this situation.
Wolfgang