fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A
  5. {
  6. public:
  7.  
  8. A()
  9. {
  10. cout << "Base constructor!" << endl;
  11.  
  12. privateVar = 10;
  13. }
  14.  
  15. void testPrint()
  16. {
  17. cout << "privateVar: " << privateVar << endl;
  18. }
  19.  
  20. private:
  21.  
  22. int privateVar;
  23. };
  24.  
  25. class B : public A
  26. {
  27. public:
  28. B()
  29. {
  30. cout << "Derived Constructor!" << endl;
  31. }
  32. };
  33.  
  34. int main() {
  35. B testB;
  36. testB.testPrint();
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Base constructor!
Derived Constructor!
privateVar: 10