#include <iostream>
using std::cout;
using std::endl;
class Shape {
protected:
float width, height;
public:
void init(float w, float h)
{
width = w; height = h;
}
virtual float area() = 0;
};
class Rectangle : public Shape {
public:
float area()
{
return width * height;
}
};
class kite : public Shape {
public:
float area()
{
return (width * height) / 2;
}
};
int main()
{
Rectangle rect;
kite kt;
// Shape sp; // Error C2259 'Shape': cannot instantiate abstract class
Shape *prect = ▭
Shape *pkt = &kt;
prect->init(7, 3);
pkt->init(7, 3);
cout << rect.area() << endl;
cout << kt.area() << endl;
return 0;
}
/*
run:
21
10.5
*/