[英]c++ compile error with visual studio
I am learning C++ and I cannot compile it. 我正在学习C ++而我无法编译它。 I am new to C++ so bear with me please. 我是C ++的新手,所以请耐心等待。
Here's a piece of code with the error: 这是一段带有错误的代码:
#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;
}
I get: 我明白了:
error LNK2020: unresolved token (0A000282) "public: static double const Car::MIN_COST" (?MIN_COST@Car@@2NB)
Thanks 谢谢
const static double MIN_COST = 10.00;
应该
const double Car::MIN_COST = 10.00;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.