The problem is that string literals such as "Hello" and "World" are of type const char[6] . This may fade to const char* , but not to char* . So overload taking const char* ,
void display(const char *p);
is the best match. As @JamesKanze points out, it would be possible for a function that takes char* to accept a string literal, but trying to modify the given data would lead to undefined behavior. For this reason, it is unsafe to pass string literals to such functions. With appropriate alert settings, GCC generates the following:
warning: deprecated conversion from string constant to 'char *
In any case, if there are two overloads like the ones you showed, the one that takes const char* wins.
source share