C++ see declaration of错误 纯虚函数问题#includeclass 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;};cla
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 14:46:29
C++ see declaration of错误 纯虚函数问题#includeclass 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;};cla
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错误 纯虚函数问题#includeclass 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;};cla
程序中变量和函数用了同样的名字weight和vaule
你return weight的时候,编译器不知道你是要返回变量weight还是返回weight函数的指针强制转double.
变量换个名字吧.比如mWeight,mValue