A follow up on type coercion in C++, as it may be construed by type conversion
- by David
This is a follow up to my previous question.
Consider that I write a function with the following prototype:
int a_function(Foo val);
Where foo is believed to be a type defined unsigned int. This is unfortunately not verifiable for lack of documentation.
So, someone comes along and uses a_function, but calls it with an unsigned int as an argument.
Here the story takes a turn. Foo turns out to actually be a class, which can take an unsigned int as a single argument of unsigned int in an explicit constructor.
Is it a standard and reliable behavior for the compiler to render the function call by doing a type conversion on the argument. I.e. is the compiler supposed to recognize the mismatch and insert the constructor? Or should I get a compile time error reporting the type mismatch.