Problem default type converting
Rupert Wood
rup@kanat.pair.com
Tue Oct 8 02:06:00 GMT 2002
On Tue, 8 Oct 2002, Henrik Nilsson (Developer) wrote:
> I'm using GCC 2.96 on Linux
:
> Then I get compiler error.
> Due to the C++ standard my.f("") should create a temp object like this
> my.f(CString("")) but instead I get compiler error
I only have 2.95 to test here, but this code (derived from yours) compiles
cleanly on full warnings:
class CString
{
public:
CString();
CString(const char *);
};
class MyClass
{
public:
void f(const CString &s);
};
int main(void)
{
MyClass my;
my.f("");
return 0;
}
and fails to link citing both MyClass::f and CString::CString(const char*).
Are you sure that you haven't made another mistake? Did you build with
'-Wall'? What's the compiler error? Does my version work?
Alternatively, have you somehow flagged the CString(const char*)
constructor as explicit-only (an __attribute__?) or forbidden implicit
construction via a command line switch? I can't see any that do that from
a quick scan of the manual.
Rup.
More information about the Gcc-help
mailing list