#include <iostream>
class Car{
public:
Car(float newSpeed = 0, double newHP = 100);
protected:
double HP;
private:
float speed;
};
Car::Car(float newSpeed, double newHP)
{
speed = newSpeed;
HP = newHP;
}
#include <vector>
using namespace std;
int main(){
Car car(10, 100);
return(0);
}
上面的代码编译时出现错误提示:“1>c:\users\aaron\documents\visual studio 2010\projects\ass3\ass3\main.cpp(9): error C2661: 'Car::Car' :没有重载函数需要 2 个参数”
我不确定为什么。我首先尝试使用 Car 构造函数的默认参数
Car::Car(float newSpeed = 0, double newHP = 100);
但这也不起作用。
我已经为此工作了3天。任何帮助深表感谢。谢谢你。
编辑:以下建议