C question about Base class and Derived class I creat a Base
C++ question about Base class and Derived class. I creat a Base class named Polygon and a Derived class named Rectangle. In the base class, we have two variables, the point x,y, and in derived class, we have width, height. Now, we creat an array of pointer Polygon *A[4]={new Rectangle}; how can I access the Rectangle function set() if we dont have the same name function set() in base class? Dose each funtion from Drived class have to be found a same name function in Base class?
#include <iostream>
 #include <cstdlib>
using namespace std;
 class Polygon
 {
 
 protected:
     int x,y;
 
 
 public:
 
 Polygon() { x = y = 0; }
 
 virtual double area()=0;
 virtual double perimeter()=0;
 virtual double center_of_gravity()=0;
 virtual ~Polygon() {cout<<\" Polygon\"<<endl;}
 
 };
 
 class Rectangle: public Polygon
 {
 protected:
 int width, height;
   
 public:
 Rectangle():Polygon(){ width=height=0;} ;
double area () { cout << \"Rectangle class area : \" << width * height << endl; }
 double perimeter() { cout << \"Rectangle class perimeter : \" << (width+height)*2<< endl; }
 double center_of_gravity() { cout << \"Rectangle class perimeter : (\"<<width/2.0+x<<\" \"<<height/2.0+y<<\")\"<<endl;}
 ~Rectangle(){cout<<\" Rectangle\"<<endl;}
 void set(int a,int b, int c, int d);
 };
   
 
 void Rectangle::set(int a,int b, int c, int d)
 {  
     x=c;
     y=d;
     width=a;
     height=b;
 }
 
 int main( )
 {
 Polygon *A[4]={new Rectangle()};  
 
     int a,b,c,d;
         cout<<\"enter the width, height and point\"<<endl;
         cin>>a>>b>>c>>d;
   
        A[0]->set(a,b,c,d);
        A[0]->area();
         A[0]->perimeter();
         A[0]->center_of_gravity();
 for(int i =0; i<4;i++)
     {
      
    delete A[i];
      
    }
 return 0;
 }
58 9 C:\\Users\\Student-Win7\\Desktop\\lab 10 error.cpp [Error] \'class Polygon\' has no member named \'set\'
this is my result.
Solution
correct the mistake by declaring the set function in class Polygon and also change the return type of function set to int .


