|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这里a.GetPeri()为什么返回0
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Shape{
- public:
- virtual float GetArea(){};
- virtual float GetPeri(){};
- };
- class Rectangle:public Shape{
- public:
- Rectangle(float w,float l): width(w),length(l){}
- float GetArea(){
- return width*length;
- }
- float GerPeri(){
- return 2*(width+length);
- }
- void p(){
- cout<<width<<endl<<length<<endl;
- }
- private:
- float width;
- float length;
- };
- void printinfo(Shape& a){
- cout<<"面积是:"<<a.GetArea()<<endl;
- cout<<"周长是:"<<a.GetPeri()<<endl; //这里返回的是0
- }
- int main(){
- Rectangle r(10.56,20.7);
- r.p();
- printinfo(r);
- }
复制代码
函数名拼写错误
- class Rectangle:public Shape{
- public:
- Rectangle(float w,float l): width(w),length(l){}
- float GetArea(){
- return width*length;
- }
- //难道不应该是 GetPeri() 吗?
- float GerPeri(){
- return 2*(width+length);
- }
复制代码
|
|