From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,3bb0dcf4dc92e48d X-Google-Attributes: gid109fba,public X-Google-Thread: fee84,3bb0dcf4dc92e48d X-Google-Attributes: gidfee84,public From: lucia@savvy.zko.dec.com (Tim Lucia) Subject: Re: Mysterious DEC OSF C++ compiler warning Date: 1995/12/20 Message-ID: <4b99kg$ktg@zk2nws.zko.dec.com>#1/1 X-Deja-AN: 122367345 distribution: world references: <4b4rog$m80@holly.cc.uleth.ca> organization: Digital Equipment Corporation reply-to: lucia@zko.dec.com newsgroups: comp.lang.c++,comp.unix.osf.osf1 #include class junk { double a; public: junk(void) {}; junk(double x) { a = x;}; junk & operator = (junk & x) { a = x.a; return(*this);}; }; main() { junk x; x = junk(2); } // ARM, 12.8 (pp. 295-296) // // If all bases and members of a class X have copy constructors accepting // const arguments, the generated copy constructor for X will take a // single argument of type const X&, as follows (double has the const ones) // // X::X(const X&) // // Otherwise it will take a single arugment of type X&: // // X::X(X&) // // Similarly, for assignment operators: // // If all bases... // // X& X::operator=(const X&) // // or // // X& X::operator=(X&) // which is what you have // // Since you declared a non-const assignment operator, then the constructor // junk(2) does not match any declared constructor (default X& X::operator=(const X&)) // so you get the warning on conversion to using the non-const one. // // use this: junk & operator = (const junk & x) { a = x.a; return(*this);}; Regards, Tim -- Timothy J. Lucia Email: mailto:lucia@zko.dec.com Digital Equipment Corporation Phone: 603.881.2615 110 Spitbrook Road ZKO2-3/K06 Fax: 603.881.0120 Nashua, NH USA 03062-2698 I'd rather be cycling.