fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // Base class
  6. class Shape {
  7. protected:
  8. int width;
  9. int height;
  10.  
  11. public:
  12.  
  13. Shape(int w,int h){
  14. width=w;
  15. height=h;
  16. }
  17.  
  18. // pure virtual function providing interface framework.
  19. virtual int getArea() = 0;
  20.  
  21.  
  22. };
  23.  
  24. // Derived classes
  25. class Rectangle: public Shape {
  26. public:
  27. int getArea() {
  28. return (width * height);
  29. }
  30. };
  31.  
  32. class Triangle: public Shape {
  33. public:
  34. int getArea() {
  35. return (width * height)/2;
  36. }
  37. };
  38.  
  39. int main(void) {
  40. Rectangle Rect(5,7);
  41. Triangle Tri(8,5);
  42.  
  43.  
  44.  
  45. // Print the area of the object.
  46. cout << "Total Rectangle area: " << Rect.getArea() << endl;
  47.  
  48.  
  49.  
  50. // Print the area of the object.
  51. cout << "Total Triangle area: " << Tri.getArea() << endl;
  52.  
  53. return 0;
  54. }
Compilation error #stdin compilation error #stdout 0s 4408KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:40:22: error: no matching function for call to ‘Rectangle::Rectangle(int, int)’
    Rectangle Rect(5,7);
                      ^
prog.cpp:25:7: note: candidate: constexpr Rectangle::Rectangle(const Rectangle&)
 class Rectangle: public Shape {
       ^~~~~~~~~
prog.cpp:25:7: note:   candidate expects 1 argument, 2 provided
prog.cpp:25:7: note: candidate: constexpr Rectangle::Rectangle(Rectangle&&)
prog.cpp:25:7: note:   candidate expects 1 argument, 2 provided
prog.cpp:41:21: error: no matching function for call to ‘Triangle::Triangle(int, int)’
    Triangle  Tri(8,5);
                     ^
prog.cpp:32:7: note: candidate: constexpr Triangle::Triangle(const Triangle&)
 class Triangle: public Shape {
       ^~~~~~~~
prog.cpp:32:7: note:   candidate expects 1 argument, 2 provided
prog.cpp:32:7: note: candidate: constexpr Triangle::Triangle(Triangle&&)
prog.cpp:32:7: note:   candidate expects 1 argument, 2 provided
stdout
Standard output is empty