Hi im trying to learn polymorphism and i stumbled upon a question. Polymorphism to me means 1 with many forms.
here is my code:
// virtual members
#include <iostream>
using namespace std;
class CPolygon {
protected:
int width, height;
public:
void display();
virtual string area ()
{ return ("FIRST"); }
};
class CRectangle: public CPolygon {
public:
string area ()
{ return ("SECOND"); }
};
void CPolygon::display(){
cout<<area()<<endl;
}
int main () {
CRectangle rect;
CPolygon poly;
CPolygon * p1 = ▭
CPolygon * p3 = &poly;
poly.display();
system("pause");
return 0;
}
basically it displays FIRST. I would like to add code to change it to display SECOND. How would i do so? any help is appreciated. i already did p1->area and such in the main code. This is me trying to learn it in a class code.