🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2261

Re: Q: is A a = 100; equivalent to A a (100); ?

#2261
From: David Sachs
Date: Thu, 19 Oct 1995 21:28
55 lines
2762 bytes
kanze@gabi-soft.fr (J. Kanze) writes:


>Matt Austern (matt@godzilla.EECS.Berkeley.EDU) wrote:

>|> In article <4638jp$ef4@fsgm01.fnal.gov> b91926@fsgm01.fnal.gov (David Sachs) writes:

>|> > X x(a) uses higher priority conversion by overloading rules
>|> > 
>|> > X x=a uses X(a.operator X&)

>|> Sort of.  If a is of class A, if the copy constructor X::X(const X&)
>|> exists, and if the converting constructor X::X(const A&) exists and
>|> isn't qualified as explicit, then "X x(a)" simply invokes the
>|> converting constructor while "X x=a" invokes the converting
>|> constructor and then the copy constructor.

>Except that there is no guarantee that the copy constructor will
>actually be invoked.  The compiler is allowed to optimize it away.

>|> Section 12.6 of the working paper explains this in detail.  The rest
>|> of chapter 12 is somewhat relevant too.

>Concerning the original posting: I don't think it will work.  As I
>understand what you are suggesting:

>    class B {} ;
>    class D : public B { operator B() ; } ;

>    D               aD ;
>    B               aB( aD ) ;
>    B               anotherB = aD ;

>What you are saying is that in the first case, D::operator B() will not
>be considered, and in the second case, it will be used.

>In fact, in both cases, it will be considered, but as a user defined
>conversion, it is pretty far down on the scale; in both cases, the
>derived->base conversion will have precedence.  (I believe.)
>  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]

I am relying on paragraph 2 of scetion 12.3.2 of the proposed standard,
which appears to specify that a conversion function will be used in
certain cases. Possibly, the draft standard is ambiguous in this area.
-- 
** The Klingons' favorite food was named by the first earthling to see it **
David Sachs - Fermilab, HPPC MS369 - P. O. Box 500 - Batavia, IL 60510
Voice: 1 708 840 3942      Deparment Fax: 1 708 840 3785


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <4668q1$1ll@fsgm01.fnal.gov>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <JLM.95Oct12202250@ludo.two-oo-one.fr> <MATT.95Oct18111956@godzilla.EECS.Berkeley.EDU> <46586t$5ai@gabi.gabi-soft.fr>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: b91926@fsgm01.fnal.gov (David Sachs)
Newsgroups: comp.std.c++
Subject: Re: Q: is A a = 100; equivalent to A a (100); ?
Date: 19 Oct 1995 21:28:42 GMT
Organization: FERMILAB, Batavia, IL
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <4668q1$1ll@fsgm01.fnal.gov>
References: <JLM.95Oct12202250@ludo.two-oo-one.fr> <MATT.95Oct18111956@godzilla.EECS.Berkeley.EDU> <46586t$5ai@gabi.gabi-soft.fr>
Reply-To: sachs@fnal.fnal.gov
NNTP-Posting-Host: physics2.berkeley.edu