C++ conversion rules ???

Marc Espie espie@quatramaran.ens.fr
Sat Jun 19 07:35:00 GMT 1999


I have trouble understanding why the following fragment:

struct A {
	operator const char *() const { return "";}
	operator char *() { return "";}
};

A a;
const char *b = a;


will yield

a.C:9: warning: choosing `A::operator char *()' over `A::operator const char *() const'
a.C:9: warning:   for conversion from `A' to `const char *'
a.C:9: warning:   because conversion sequence for the argument is better

even after reading the ANSI C++ drafts I have...

Note that, if I remove one const,  e.g.,
	operator const char *() { return "";}
the code no longer warns...



More information about the Gcc mailing list