i am getting an error message "Allocating an object of abstract class type 'Shape'". Circle(double r):Shape("Circle").
#include <iostream>
using namespace std;
class Shape{
char name[20];
Shape(char *){};
virtual double getPerimeter()=0;
virtual double getArea()=0;
};
class Circle : public Shape{
double rad;
static const double PI;
public:
Circle(double r):Shape("Circle"){
rad = r;
}
double getRadius(){
return rad;
}
double getPerimeter(double rad){
return 2 * PI * rad;
}
double getArea(double rad){
return PI * (rad * rad);
}
};
class Square : public Shape{
double side;
public:
Square(double s):Shape("Square"){
side = s;
}
double getPerimeter(double side){
return side * 4;
}
double getArea(double side){
return side * side;
}
};
const double Circle::PI = 3.1415;
int main(){
}
Is this a problem with the constructor in Class Circle/Square? Im not sure and a bit lost. At this point any hints of what i should research to find the answer would be great.
Thanks!
The signatures of getArea
and getPerimeter
differs from those of the base class. Use the same signature, otherwise you're just hiding the base methods, not overriding them.
You don't need to pass in the dimensions, you already have them as members.