Access to private data type of an outer class from inner class

A

agentprog

Hello!

I have a container class, its structure is implemented using private structure. And i would like to implement something like iterator and it should be able to have a pointer to that private structure.

class Container {
public:
// ...
class Iterator {
// ...
private:
//Container::node *ptr;
node *ptr;
};
private:
struct node {
// ...
};
// ...
};

Compiler does not allow me to do that even if Iterator is a friend of Container.
Is there a way to access Container::node from Container::Iterator or maybe i should rethink the whole design?

If it makes sense, i use g++ (4.6.3) as a compiler in c++03 standard mode.
 
S

Stefan Ram

Is there a way to access Container::node from Container::Iterator or maybe i should rethink the whole design?

You need a forward declaration.

class Container { private: struct alpha; /* :forward declaration */
public: class Iterator{ ::Container::alpha *p; }; private: struct alpha {}; };
int main(){}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top