> Since inner classes are *members* of the outer class, they have access
> to all other members of that class, yes. Just like member functions
> of the class have access to other members of the same class. The
> reverse is not true, if memory serves. The members of the outer class
> cannot access private or protected members of the inner class without
> being friends of the inner class.
If you remove the pointer to the Outer class from the Inner class and
give to Inner a default constructor instead of the one coded in my
example when you try to access x directly, the compiler says:
In member function ‘void Outer::Inner::setx(int)’:
error: invalid use of nonstatic data member ‘Outer::x’
So It is not true you can access data members of Outer from inside Inner.
> What's the task? Accessing the member is the mean, what's the goal?
Have you ever attended a science class when you were at school?
your chemistry teacher probably told you that an acid and a base make
a salt and that the resulting solution heats and you probably wanted
to test it by your own in the lab [or worst at home], just to fix your
ideas.
Ok my example probably doesn't fit good, but I hope it explains why I
have to try that statement. Yes, the task is try to access the member
of the outer class directly from within the inner class. I was not
able to do it without that tricky pointer to the Outer class made it
be pointed to an instance of the Outer class.
> > Two solutions came to my mind, namely
>>
>> make the inner class a friend of the outer class
>> make the inner class to inherit from outer
>>
>> but both ways I was unable to properly set up.
>> Could you tell me if these two methods can be successfully be applied?
>
> I am not sure how you'd make the inner class derive from the outer,
the compiler doesn't let me derive Inner from Outer but I thought
it a fault in my code.
> but friendship can be established in either direction.
I know that, but in this case too, I was not be able to access x
directly.