I have been trying to understand this and to find some information about definition of struct type inside a class (for C++). However, I have not find yet any good clarification to my actual doubt. In case we have the following definition
namespace MyOuterNamespace {
namespace MyInnerNamespace {
class MyClass {
struct MyStruct {
int myVar;
};
MyStruct m_MyStruct;
};
}
}
Here in this sample code the m_MyStruct is a private member, so it cannot be access from the outside. However the struct definition is accessible and we can declare a struct variable of this type in any place with
MyOuterNamespace::MyInnterNamespace::MyClass::MyStruct outsideStruct;
What is the principal to make this possible. If the structure is defined as a type in the private section of the class, why is possible to use it from outside? Is this working only as "namespace" for the structure definition. It is not actually hidden as the struct variable.
I have found out several articles but maybe this answer from a similar thread is actually answering and giving the principal of how this is understood by the language: Nested structures
Can anybody confirm this or provide a better explanation?
[EDIT] You can do this for public definitions but for private you face the expected visibility error.
Thanks!