nested-classes/nested-2a.cpp - A variant where class Inner is private in Outer - does not compile. | Lecture 5 - slide 12 : 40 Program 3 |
// For exercise. // In starting point reproduced from page 851-852 of "The C++ Programming Language", 3ed version. // With mutual friendship between Outer and Inner classes. // In this version class Inner is private in class Outer. Does not compile. #include <iostream> #include <string> class Outer{ private: typedef int T; int i; class Inner{ // Inner is now private in Outer friend class Outer; // Outer is still a friend private: int x; T y; public: void fi(Outer *p, int v); }; Inner ii; public: int i2; static int s; int fo(Inner* p); }; void Outer::Inner::fi(Outer *op, int v){ op->i = v; op->i2 = v; } int Outer::fo(Inner* ip){ ii.fi(this,3); ip->fi(this,2); return ip->x; } int main(){ Outer o; Outer::Inner i; // error: class Outer::Inner is private i.fi(&o, 5); }