C++求救
下面这个程序为什么是错的?怎么错了,要怎么改呢?谢谢大家了。#include<iostream>
using namespace std;
class Shape
{
public:
virtual float printArea() const=0;
};
class Circle:public Shape
{
public:
Circle(float a):r(a){}
virtual float printArea()const
{cout<<"Circle'area:"<<3.1514*r*r<<endl;}
protected:
float r;
};
class Rectangle:public Shape
{
public:
Rectangle(float a,float b):w(a),l(b){}
virtual float printArea()const
{cout<<"Rectangle'area:"<<w*l<<endl;}
protected:
float w;
float l;
};
class Triangle:public Shape
{
public:
Triangle(float a,float b):w(a),h(b){}
virtual float printArea()const
{cout<<"Triangle'area:"<<0.5*w*h<<endl;}
protected:
float w;
float h;
};
int main()
{
Circle c(8);
Rectangle r(5,8);
Triangle t(2.6,6);
Shape*p=&c;
p->printArea();
Shape*p=&r;
p->printArea();
Shape*p=&t;
p->printArea();
return 0;
}