C++ see declaration of错误 纯虚函数问题
#include
class vehicle
{
protected:
double weight;
double vaule;
public:
vehicle(double weight,double vaule)
{
vehicle::weight=weight;
vehicle::vaule=vaule;
}
virtual double weight()=0;
virtual double vaule()=0;
};
class car:public vehicle
{
public:
car(double weight,double vaule):vehicle(weight,vaule){};
double weight()
{
return weight;
}
double vaule()
{
return vaule;
}
};
class truck:public vehicle
{
public:
truck(double weight,double vaule):vehicle(weight,vaule){};
double weight()
{
return weight;
}
double vaule()
{
return vaule;
}
};
class boat:public vehicle
{
public:
boat(double weight,double vaule):vehicle(weight,vaule){};
double weight()
{
return weight;
}
double vaule()
{
return vaule;
}
};
void main()
{
vehicle *p;
car c1(1000.0,20000.0);
truck t1(3000.0,100000.0);
boat b1(9000.0,2000000.0);
p=&c1;
cout
C++ see declaration of错误 纯虚函数问题
答案:2 悬赏:60 手机版
解决时间 2021-12-22 11:43
- 提问者网友:呐年旧曙光
- 2021-12-21 16:58
最佳答案
- 五星知识达人网友:持酒劝斜阳
- 2021-12-21 17:34
程序中变量和函数用了同样的名字weight和vaule
你return weight的时候,编译器不知道你是要返回变量weight还是返回weight函数的指针强制转double.
变量换个名字吧.比如mWeight,mValue
全部回答
- 1楼网友:煞尾
- 2021-12-21 17:45
谢谢了
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯