I put a class into another class. I put a reference of the highest level class into the lower level class (not sure if there's a nomenclature for this.. not child/parent..? subclass?). I am very surprised to see that I can call private functions from that sub class. Why is this possible?
Simple example: I am surprised Bar can call a private function from Foo
// Example program #include <iostream> #include <string> class Foo { public: class Bar { public: Bar(Foo &foo); void DoFoo(); private: Foo &foo; }; Foo(); private: void Do(); }; Foo::Foo(){} void Foo::Do(){ std::cout << "im doing foo"; } Foo::Bar::Bar(Foo &foo) :foo(foo) { }; void Foo::Bar::DoFoo(){ this->foo.Do(); } int main() { Foo foo; Foo::Bar bar(foo); bar.DoFoo(); }