#include<iostream.h>
#include<math.h>
#define PI 3.1415
class CBase
{public:
virtual float area(){return 0.0;}
protected:
float a;
CBase(float x){a=x;}
};
class Tria:public CBase
{protected:
float b;float c;
public:
Tria(float x,float y,float z):CBase(x)
{b=y;c=z;}
float area()
{float l=(a+b+c)/2;
return sqrt(l*(l-a)*(l-b)*(l-c)); }
};
class Square:public CBase
{protected:
float area()
{return a*a;}
};
class Round:public CBase
{protected:
float area()
{return PI*a*a;}
};
void print(CBase &p)
{cout<<p.area()<<endl;}
void main()
{
Tria e(3.3f,5.2f,8f);
cout<<"三角形的面积为:\t";
print(a);
Square f(6.0f);
cout<<"正方形的面积为:\t";
print(f);
Round g(1.5f);
cout<<"圆形的面积为:\t";
print(g);
}
--------------------Configuration: S1 - Win32 Debug--------------------
Compiling...
1.cpp
C:\Documents and Settings\KING\桌面\新建文件夹\S1\1.cpp(20) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
C:\Documents and Settings\KING\桌面\新建文件夹\S1\1.cpp(32) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
C:\Documents and Settings\KING\桌面\新建文件夹\S1\1.cpp(38) : error C2059: syntax error : 'bad suffix on number'
C:\Documents and Settings\KING\桌面\新建文件夹\S1\1.cpp(38) : error C2146: syntax error : missing ')' before identifier 'f'
C:\Documents and Settings\KING\桌面\新建文件夹\S1\1.cpp(38) : error C2059: syntax error : ')'
C:\Documents and Settings\KING\桌面\新建文件夹\S1\1.cpp(40) : error C2065: 'a' : undeclared identifier
C:\Documents and Settings\KING\桌面\新建文件夹\S1\1.cpp(41) : error C2664: 'Square::Square' : cannot convert parameter 1 from 'const float' to 'const class Square &'
Reason: cannot convert from 'const float' to 'const class Square'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Documents and Settings\KING\桌面\新建文件夹\S1\1.cpp(44) : error C2664: 'Round::Round' : cannot convert parameter 1 from 'const float' to 'const class Round &'
Reason: cannot convert from 'const float' to 'const class Round'
No constructor could take the source type, or constructor overload resolution was ambiguous
执行 cl.exe 时出错.
主函数之前的程序都没有错误,但是编完主函数就这样叻,请教一下怎么改正?