fork(3) download
  1. #include <iostream>
  2.  
  3. class Base
  4. {
  5. private:
  6. Base() {}
  7. friend class Derived1;
  8. friend class Derived2;
  9. };
  10.  
  11. class Derived1 : public Base
  12. {
  13. };
  14.  
  15. class Derived2 : public Base
  16. {
  17. };
  18.  
  19. int main() {
  20.  
  21. Derived1 obj;
  22. Base obj2; // Error
  23.  
  24. return 0;
  25. }
Compilation error #stdin compilation error #stdout 0s 3340KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:6:2: error: ‘Base::Base()’ is private
  Base() {}
  ^
prog.cpp:22:7: error: within this context
  Base obj2; // Error
       ^
stdout
Standard output is empty