This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Implicit conversion error using g++
On Jul 9, 2001, David Berthelot <davidb@Magma-DA.COM> wrote:
> Ok, please correct me if I am wrong.
No problem :-)
> 1. Line 13 and 14 are not "equivalent" (whatever this word may mean)
> because they translate into different function calls:
> Line 13 would be replaced by these calls:
> - bar.Foo()
> - Baz(const Foo&)
> Line 14 would be replaced by:
> - Baz()
> - Baz.operator=(const Bar)
> I think that the missing operator= is the reason why the automatic casting
> doesn't work in your code.
Nope. Both lines perform object initialization, so the assignment
operator plays no role. The difference is that `Baz b1(bar)' is a
direct initialization, whereas `Baz b2 = bar' is a copy
initialization. The former may use a user-defined conversion sequence
plus a constructor, but the latter needs a single user-defined
conversion sequence, that can contain either a constructor or a
conversion function. See [dcl.init]/11-14 for details.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me