Let's say I have a class:
class String
{
public:
String(char *str);
};
And two functions:
void DoSomethingByVal(String Str);
void DoSomethingByRef(String &Str);
If I call DoSomethingByVal like this:
DoSomethingByVal("My string");
the compiler figures out that it should create a temporary String object and call the char* constructor.
However, if I try to use DoSomethingByRef the same way, I get a "Can't convert parameter from 'char *' to 'String &'" error.
Instead, I have to explicitly create an instance:
DoSomethingByRef(String("My string"));
which can get preety annoying.
Is there any way to avoid this?