| <<< Conversion by constructor | Index | Functors >>> |
Sometimes we are better off without constructor-conversions:
class String {
public:
String( int i ) // Innocent idea: set initial size!
{
//...
}
};
String foo()
{
return 0; // probably a typo?!
}
void bar( String const& str )
{
//...
}
int main( )
{
String s1(4); // OK
String s2 = 4; // Confusing
String s3 = foo(); // Really??
bar(4); // Error??
return 0;
}
FYI: the above compiles just fine!
Better solution: make constructor taking a single size argument explicit.
| <<< Conversion by constructor | Index | Functors >>> |