I am trying to implement a private struct or class within another struct. Case I works whereas case II is possible after declaration all member variables as public. why so? I am aware that by default all member variables/functions in struct are public and vice versa in a class definition. Now I am a bit confuse why case II don't work? Any thought?
// case I
// case II
char name_; // not accessible by impl member func if private
Case I works whereas case II is possible after declaration all member variables as public. why so? (not accessible by impl member func if private)
Only public members are accessible outside the class. Since member function of
impl is outside the class
pod_t, only public members of
pod_t are available.
P.S. Your case I and II are different besides the access specifier of the member. In case I you have an object by the name
pod_t whose type is an unnamed class. In case II you have a class by the name
pod_t and no objects of that class.