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, *b;
  11.  
  12. Shape() {
  13. a = &width;
  14. b = &height;
  15. }
  16.  
  17. Shape(const Shape &src) : Shape() {
  18. width = src.width;
  19. height = src.height;
  20. }
  21.  
  22. Shape(Shape &&src) : Shape() {
  23. width = src.width;
  24. height = src.height;
  25. }
  26. };
  27.  
  28. class Rectangle : public Shape {
  29. public:
  30. void setWidth(int w) { *a = w; }
  31. void setHeight(int h) { *b = h; }
  32. int getArea() { return (*a * *b); }
  33. };
  34.  
  35. int main() {
  36. Rectangle Rect;
  37. Rect.setWidth(5);
  38. Rect.setHeight(7);
  39.  
  40. cout << "Total area: " << Rect.getArea() << endl;
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Total area: 35