fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class base
  5. {
  6. int data1B_;
  7. public:
  8. int data2B_;
  9. base()
  10. {
  11. cout << "you are in base class constructor" << '\n';
  12. data1B_ = 10;
  13. data2B_ = 20;
  14.  
  15. }
  16. int f(int g)
  17. {
  18. return (g);
  19. }
  20. int g(int f)
  21. {
  22. return (f);
  23. }
  24.  
  25. };
  26.  
  27. class derived : public base
  28. {
  29. int infoD_;
  30. public :
  31. derived() {cout << "you are in derived class constructor" << '\n';}
  32. };
  33. int main() {
  34. // your code goes here
  35.  
  36. int result;
  37. base b1;
  38. derived d1;
  39. result = d1.f(5);
  40. cout << result << '\n';
  41.  
  42. result = d1.g(10);
  43. cout << result << '\n';
  44.  
  45. result = b1.f(5);
  46. cout << result << '\n';
  47. return 0;
  48. }
Success #stdin #stdout 0s 4292KB
stdin
Standard input is empty
stdout
you are in base class constructor
you are in base class constructor
you are in derived class constructor
5
10
5