Hello,
can someone please tell me, why it's possible to access the member of a returned private nested struct? Shouldn't the compiler complain about the privateness of the returned data type?
Thanks,Code:#include <iostream> using std::cout; using std::endl; class TestClass { private: struct TestStruct { int A, B, C; }; public: TestStruct get() { TestStruct t = { 1, 2, 3 }; return t; } }; int main( int argc, char **argv ) { TestClass *t = new TestClass(); // Here the compiler mourns about privateness - as expected TestClass::TestStruct e = t->get(); // This one works, but why? int a = t->get().A; }
egrath



LinkBack URL
About LinkBacks



