A
Angus
Hello
I have some classes defined in shapes.h and use them like this:
const IShape* rectangle = new Rectangle(10.0, 20.0); // width, height
cout << rectangle->calculateArea() << endl;
delete rectangle; // causes error C2665 error
Error I get is:
error C2665: 'delete' : none of the 2 overloads can convert parameter 1 from
type 'const class IShape *'
My shapes.h
class IShape
{
public:
virtual double calculateArea() const = 0; // returns area
};
class Rectangle : public IShape
{
public:
Rectangle(double width, double height)
{
m_width = width;
m_height = height;
}
double calculateArea() const
{
return m_width * m_height;
}
double m_width; // width
double m_height; // height
};
class Circle : public IShape
{
public:
Circle(double radius)
{
m_radius = radius;
}
double calculateArea() const
{
return 2 * PI * m_radius;
}
double m_radius; // radius of circle
static const double PI = 3.14;
};
How do I fix this?
I have some classes defined in shapes.h and use them like this:
const IShape* rectangle = new Rectangle(10.0, 20.0); // width, height
cout << rectangle->calculateArea() << endl;
delete rectangle; // causes error C2665 error
Error I get is:
error C2665: 'delete' : none of the 2 overloads can convert parameter 1 from
type 'const class IShape *'
My shapes.h
class IShape
{
public:
virtual double calculateArea() const = 0; // returns area
};
class Rectangle : public IShape
{
public:
Rectangle(double width, double height)
{
m_width = width;
m_height = height;
}
double calculateArea() const
{
return m_width * m_height;
}
double m_width; // width
double m_height; // height
};
class Circle : public IShape
{
public:
Circle(double radius)
{
m_radius = radius;
}
double calculateArea() const
{
return 2 * PI * m_radius;
}
double m_radius; // radius of circle
static const double PI = 3.14;
};
How do I fix this?