"Old Wolf" <ol*****@inspire.net.nz> schrieb:
std::string foo()
{
std::string s;
return some_condition() ? s : "";
}
saying that the last two operands of ?: must be the same type. I
have to fix it by changing "" to std::string() .
Is this correct behaviour? I remember reading that the compiler
ought to try implicitly converting one of the operands to the type
of the other.
I would also suggest to fix this as you describe it yourself.
Otherwise the compiler looks for an implicit constructor matching a
const char* parameter. If your code is compiled with a STL
implementation using explicit constructors the compiler will not use
even a matching constructor.
I find implicit constructors bad style because people beeing not
familiar with this (especially beginners) don't even know that there's
a constructor and from what class. It's the same with function
parameters.
T.M.