I've a (member-)fuction overloaded like this:
bool foo(bool);
int foo(int);
float foo(float);
...
std::string foo( std::string const&);
for a couple of build-in-types but not for const char*
. Calling foo("beauty is only skin-deep");
, to my big suprise, called the bool-variant of the foo function. This leads to my questions:
QUESTION: Is there a well defined implicit conversion order for build-in-types
NOT THE QUESTION: How to avoid implicit conversion. How evil is implicit conversion. ...
EDIT: removed question about implicit converstion order for user-defined-questions
according to: http://en.cppreference.com/w/cpp/language/implicit_cast
all build-in conversions take place before user defined ones
pointer -> bool is a 'Boolean conversions' (needed for if(pointer) notation), last of 'numeric conversions'
'const char*' -> std::string is a 'user defined conversion' as from language point of view, std::string is a user defined type.
Unfortunately simplest solution is to write proper overload of fun(const char*), or to avoid fun(bool) vs fun(std::string) overloads
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With