This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem default type converting


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.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]