Given the following code without considering friendship between two classes:
class OutSideClass
{
...
public:
int i_pub;
protected:
int i_pro;
private:
int i_pri;
class InSideClass
{
...
public:
int j_pub;
protected:
int j_pro;
private:
int j_pri;
};
};
Question 1> Is it true that OutSideClass can ONLY access public members of InSideClass
Question 2> Is it true that InSideClass can access all members of OutSideClass
Please correct me if my understanding is not correct.
Yes
No, in C++03. Yes, in C++11.
The Standard text is very clear about this:
The C++ Standard (2003) says in $11.8/1 [class.access.nest],
However, the Standard quotation has one defect. It says the nested classes don’t have access to private members of the enclosing class. But in C++11, it has been corrected: in C++11, nested classes do have access to private members of the enclosing class (though the enclosing class still doesn’t have access to private members of the nested classes).
See this Defect Report :