fork(12) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class base
  6. {
  7. friend class derived; //<======= note this line
  8. private:
  9. base()
  10. {
  11. cout << "base: ctor()\n";
  12. }
  13. };
  14.  
  15. class derived: public base
  16. {
  17. public:
  18. derived()
  19. {
  20. cout << "derived: ctor()\n";
  21. }
  22. };
  23.  
  24. int main()
  25. {
  26. derived d;
  27. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
base: ctor()
derived: ctor()