[comp.lang.c++] overloaded functions

jjc@jclark.UUCP (James Clark) (05/30/89)

I was wondering whether the C++ rules for overloaded function names
could not be a little smarter. For example, the following won't
compile (with cfront 1.2 or g++):

struct SubString {
};

struct String {
  String(SubString &);
  operator char *();
};

String operator+(String &, String &);
String operator+(String &, const char *);

String foo(SubString &s, String &t)
{
  return s + t;
}
  
The choice here is between:

- converting s to a String and doing nothing to t; and

- converting s to a String and converting t to a char *.

It would be nice if C++ was able to do the right thing, and choose the
first. Is there some good reason why it doesn't?

James Clark
jjc@jclark.uucp