fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Shape {
  5. private:
  6. int width;
  7. int height;
  8.  
  9. public:
  10. int *a = &width, *b = &height;
  11.  
  12. Shape() = default;
  13.  
  14. Shape(const Shape &src) : Shape() {
  15. width = src.width;
  16. height = src.height;
  17. }
  18.  
  19. Shape(Shape &&src) : Shape() {
  20. width = src.width;
  21. height = src.height;
  22. }
  23. };
  24.  
  25. class Rectangle : public Shape {
  26. public:
  27. void setWidth(int w) { *a = w; }
  28. void setHeight(int h) { *b = h; }
  29. int getArea() { return (*a * *b); }
  30. };
  31.  
  32. int main() {
  33. Rectangle Rect;
  34. Rect.setWidth(5);
  35. Rect.setHeight(7);
  36.  
  37. cout << "Total area: " << Rect.getArea() << endl;
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
Total area: 35