fork(1) download
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::endl;
  5.  
  6. /* Class Shape */
  7. class Shape
  8. {
  9. protected:
  10. int width, height;
  11. public:
  12. Shape( int a=0, int b=0)
  13. {
  14. width = a;
  15. height = b;
  16. }
  17.  
  18. int area()
  19. {
  20. cout << "Parent class area :" <<endl;
  21. return 0;
  22. }
  23. };
  24.  
  25.  
  26. /* Class Triangle */
  27. class Triangle: public Shape
  28. {
  29. public:
  30. Triangle( int a=0, int b=0)
  31. {
  32. Shape(a, b);
  33. }
  34. int area ()
  35. {
  36. cout << "Triangle class area :" <<endl;
  37. return (width * height / 2);
  38. }
  39. };
  40.  
  41. int main( )
  42. {
  43. Triangle tri(10,7);
  44.  
  45. tri.Shape::area();
  46.  
  47. std::cout << " versus " << std::endl;
  48.  
  49. tri.Triangle::area();
  50. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Parent class area :
 versus 
Triangle class area :