fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class MyParentClass {
  5. public:
  6. MyParentClass (int x=0) : MyInt(x) {}
  7. int MyInt;
  8. };
  9.  
  10. class MyChildClass : public MyParentClass
  11. {
  12. public:
  13. MyChildClass () = default;
  14. MyChildClass (int x) : MyParentClass(x) {}
  15. MyChildClass (const MyParentClass& x) : MyParentClass(x) {}
  16. };
  17.  
  18. int main() {
  19. MyParentClass p = 10;
  20. MyChildClass c = 5;
  21. MyChildClass d = p;
  22. cout << c.MyInt <<endl;
  23. cout << d.MyInt <<endl;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 4496KB
stdin
Standard input is empty
stdout
5
10