fork download
  1. class myClass {
  2. int y; // Regular variable
  3. myClass() : x (1) {}
  4. void foo1 () {x.x++; y++;} // This can change x
  5. void foo2 () {x.x--; y--;} // This shouldn't be able to change x
  6. // I want it to throw a compile error
  7. class subClass {
  8. friend void myClass::foo1() ; // This must come after the declaration of foo1
  9. int x ; // private
  10. public:
  11. subClass (int x) : x (x) { }
  12. int read_x() const { return x ; }
  13. } x ;
  14. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘void myClass::foo2()’:
prog.cpp:9: error: ‘int myClass::subClass::x’ is private
prog.cpp:5: error: within this context
stdout
Standard output is empty