问题
I was asked that in a method class receive a char* and copy that in the member of the class, and if I don´t receive any parameter assign "Sin nombre" to the parameter
void VEHICULO::Set_Nombre(const char* c){
//No problem here
}
int main(){
VEHICULO a;
a.Set_Nombre("FERRARI");//ITS OK
a.Set_Nombre(); //the class doesnt know that method
}
know how to copy the passed char* or copy "Sin nombre", but when in main I call without a parameter the class doesn´t recognize it, and it should work with the same method, I can´t code the method Set_Nombre(void)
回答1:
C++ default arguments.
void VEHICULO::Set_Nombre(const char* c = "Sin Nombre")
{
}
来源:https://stackoverflow.com/questions/56724417/how-can-i-overload-char