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]

Re: Implicit conversion error using g++


Alexandre Oliva wrote:

> 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.

Ok, I get it. In fact line 14 would translate by:
- Baz(const Foo&) (right hand side of equal)
- Baz(const Baz&) (for b2)
Am I correct ?

So the code is supposed to work ? Then, is it a compiler failure ?

--
David Berthelot



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