3
我正在學習C++,我無法編譯它。我是C++新手,請耐心等待。與Visual Studio的C++編譯錯誤
下面是一段代碼與錯誤:
#include<iostream>
#include<string>
using namespace std;
class Car {
private:
int carId;
string mechanicName;
double cost;
public:
const static double MIN_COST;
Car(int, string = "Mike", double = MIN_COST);
void display();
};
const static double MIN_COST = 10.00;
Car::Car(int id, string name, double amt) {
carId = id;
mechanicName = name;
cost = amt ;
}
void Car::display() {
cout << "Car #" << carId << " processed by " <<
mechanicName << " Total due $" << cost << endl;
}
int main() {
cout << "Service: " << endl << "Cars Worked on Today" <<
endl << endl;
cout << "Minimum cost $" << Car::MIN_COST << endl << endl;
Car car1();
Car car2(321);
Car car3(456,"Amy");
Car car4(567,"Jeremy",149.99);
car2.display();
car3.display();
car4.display();
return 0;
}
我得到:
error LNK2020: unresolved token (0A000282) "public: static double const Car::MIN_COST" ([email protected]@@2NB)
感謝
謝謝,我還發現我應該這樣做的地方'Car(int,string =「Joe」,double = Car :: MIN_COST);'這樣做可以嗎? –
是的,這也應該工作。 –
謝謝,我很感激 –