fork download
  1. #include <iostream>
  2. using std::cout;
  3. using std::endl;
  4.  
  5. class Base {
  6. protected:
  7. int x;
  8. int y;
  9. public:
  10. Base(int y) : y(y) {};
  11. int getX() {
  12. return x;
  13. }
  14. };
  15.  
  16. class Derived : public Base {
  17. public:
  18. Derived(int y) : Base(y) { x = 40; }
  19. };
  20.  
  21. int main() {
  22. Derived d(10);
  23. cout << d.getX() << endl;
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5544KB
stdin
Standard input is empty
stdout
40