Açıklama Yok

inh01.cpp 635B

1234567891011121314151617181920212223242526272829303132333435
  1. // Example showing a base class (Shape) and a derived
  2. // class Rectangle. Notice how Rectangle inherits Shape's
  3. // display function.
  4. #include <iostream>
  5. using namespace std;
  6. class Shape {
  7. protected:
  8. int width, height;
  9. public:
  10. Shape() { width = height = 0; }
  11. Shape(int w, int h) { width = w; height = h; }
  12. void display() const;
  13. };
  14. void Shape::display() const {
  15. cout << width << " " << height << endl;
  16. }
  17. class Rectangle : public Shape {
  18. public:
  19. Rectangle() {}
  20. Rectangle(int w, int h) : Shape(w, h) {}
  21. };
  22. int main() {
  23. Rectangle r;
  24. Rectangle q(4,5);
  25. r.display();
  26. q.display();
  27. return 0;
  28. }