fork download
  1. #include <iostream>
  2. using namespace std; class A
  3. { int x; public:
  4. A(int val)
  5. { x = val; }
  6.  
  7. int getX() const
  8. { return x; }
  9. };
  10.  
  11. class B
  12. { int y;
  13. public:
  14. B(const A& obj)
  15. { y = obj.getX(); }
  16.  
  17. void show()
  18. { cout << "y = " << y << endl; }
  19. };
  20. int main()
  21. { A objA (10);
  22. B objB = objA;
  23. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty