-1

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 Answers1

1

C++ default arguments.

void VEHICULO::Set_Nombre(const char* c = "Sin Nombre")
{
}
Michael Chourdakis
  • 10,345
  • 3
  • 42
  • 78