fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Base {
  6. private:
  7. int a;
  8. public:
  9. Base(){}
  10. Base( int a ) : a(a) { }
  11.  
  12. Base& operator=(const Base& rhs) = delete;
  13. Base(const Base& rhs) {}
  14. void setA(int a){ this->a = a;}
  15. int getA(){ return a;}
  16. };
  17.  
  18. class Derived : public Base {
  19. public:
  20. int getB(){ return b;}
  21. Derived(int b) : b(b){}
  22.  
  23.  
  24. Derived& operator=(const Derived& rhs){
  25. this->b = rhs.b;
  26. }
  27. private:
  28. int b;
  29. };
  30.  
  31. int main() {
  32. Base b(3);
  33. Derived d(9);
  34. d.setA(44);
  35.  
  36. Derived cd = d;
  37.  
  38.  
  39. cout << cd.getA() << " " << cd.getB() << endl;
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
0 9