showCarInfo(mycar); は失敗する理由がわかりません。
教えてください。
#include <iostream>
using namespace std;
class Car{
//private:
public:
int number;
int gas;
Car(int n = 0, int g = 0){number = n; gas = g;} // Constractor
void showCarInfo(Car& c); // Member function
void show();
};
int main(){
Car mycar(2, 4);
showCarInfo(mycar); // Error
mycar.show(); // Okay
return 0;
}
// Member function
void Car::showCarInfo(Car& c){
cout<<"The car number is "<< c.number <<endl;
cout<<"The gas is "<< c.gas <<".\n";
}
void Car::show(){
cout<<"The car number is "<< number <<endl;
cout<<"The gas is "<< gas <<".\n";
}