How can I overload char*? [duplicate]

偶尔善良 提交于 2019-12-25 18:42:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!