#include<iostream>
using namespace std;
//定义shape基类
class shape
{
public:
virtual double calculate() = 0;//定义虚函数calculate
};
//定义trapezoid类
class trapezoid
{
protected:
double length1, length2, high;
public:
trapezoid(double l1, double l2, double h)
{
length1 = l1; length2 = l2; high = h;
}
virtual double const calculate()
{
return (((length1 + length2)*high) / 2);
}
};
//定义circle类
class circle :public shape
{
protected:
double radius;
public:
circle(double r)
{
radius = r;
}
virtual double calculate()
{
return(3.1415926*radius);
}
};
//定义rectangule类
class rectangle
{
protected:
double width, length;
public:
rectangle(double w, double l)
{
width = w; length = l;
}
virtual double calculate()
{
return(width*length);
}
};
void main()
{
rectangle r(10, 10);
circle c(10);
trapezoid t(10, 10, 10);
shape* a[3];
a[1] = &r;
}
在main函数的最后一行出错,求大神指点