C++简单的问题
#include <iostream>#include <cmath>
using namespace std;
class Shape
{
public:
virtual Shamename() const=0;
virtual area() const=0;
};
class Circle:public Shape
{
public:
Circle(double r):radius(r) {}
virtual Shamename() {cout<<"Circle:"<<endl;}
virtual double area(){return 3.1415926*radius*radius;}
protected:
double radius;
};
class Rectangle:public Shape
{
public:
Rectangle(double a,double b):length(a),with(b) {}
virtual Shamename(){cout<<"Rectangle:"<<endl;}
double area() {return length*with;}
protected:
double length,with;
};
class Triangle:public Shape
{
public:
Triangle(double a,double b,double c):bord1(a),bord2(b),bord3(c) {}
virtual Shamename(){cout<<"Rectangle:"<<endl;}
double area()
{
double s=(bord1+bord2+bord3)/2;
return sqrt(s*(s-bord1)*(s-bord2)*(s-bord3));
}
protected:
double bord1,bord2,bord3;
};
void printArea(const Shape &s)
{
cout<<s.Shamename()<<endl;
cout<<s.area()<<endl;
}
void main()
{
Circle c1(2);
printArea(c1);
}
错在哪里啊