File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
13_virtual_function_and_abstract_class Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,9 @@ class Shape
2323 }
2424
2525 // instance member function to display the area
26- virtual void displayArea ()
26+ virtual void displayArea () const
2727 {
28+ cout << " \n Not Implemented this for class Shape..." ;
2829 }
2930};
3031
@@ -33,7 +34,7 @@ class Triangle : public Shape
3334{
3435public:
3536 // instance member function to display the area
36- void displayArea ()
37+ void displayArea () const override
3738 {
3839 cout << " \n Area of Triangle => " << 0.5 * d1 * d2;
3940 }
@@ -44,22 +45,24 @@ class Rectangle : public Shape
4445{
4546public:
4647 // instance member function to display the area
47- void displayArea ()
48+ void displayArea () const override
4849 {
4950 cout << " \n Area of Rectangle => " << d1 * d2;
5051 }
5152};
5253
5354int main ()
5455{
55- Rectangle r1;
56- r1.setData (4 , 5 );
57- r1.displayArea ();
58-
56+ // // create an instance of Triangle
5957 Triangle t1;
6058 t1.setData (4 , 3 );
6159 t1.displayArea ();
6260
61+ // // create an instance of Rectangle
62+ Rectangle r1;
63+ r1.setData (4 , 5 );
64+ r1.displayArea ();
65+
6366 cout << endl; // Add new line
6467 getch ();
6568 return 0 ;
You can’t perform that action at this time.
0 commit comments