Article View: comp.std.c++
Article #2241Re: Q: is A a = 100; equivalent to A a (100); ?
From: David Sachs
Date: Wed, 18 Oct 1995 17:57
Date: Wed, 18 Oct 1995 17:57
60 lines
2698 bytes
2698 bytes
damian@molly.cs.monash.edu.au (Damian Conway) writes: >kanze <kanze@lts.sel.alcatel.de> writes: >>In article <45sl3a$coc@engnews2.Eng.Sun.COM> clamage@Eng.sun.com >>(Steve Clamage) writes: >>|> damian@molly.cs.monash.edu.au (Damian Conway) writes: >>|> >Then is it possible to set up a class X wherein: >>|> > X x(1); >>|> >and >>|> > X x = 1; >>|> >behave differently? >>|> Yes. Silly example: Write a message to the terminal from the copy >>|> constructor. If the copy is optimized away, you won't see the message. >>I don't think that is what he was looking for. As far as I know, >>there is no way of *ensuring* that the above will both be legal, but >>have garanteed different run-time semantics. >Yes, that was what I was asking. >>It is trival to make the first legal, and the second illegal, which, I >>suppose is a way of making them behave differently at compile time. >:-) >BTW: What was the rationale for making something as fundamental as copy > initialization non-portable (in the sense that it has no guaranteed > semantics)? While it is not easy to write an example in which X x(1); and X x = 1; are guaranteed to behave differently, it is quite easy to produce a case in which X x(a); and X x=a; behave differently, where a is a class object, of a class that has a conversion operator to X&, and another higher priority conversion to something accepted by a constructor of class X. then: X x(a) uses higher priority conversion by overloading rules X x=a uses X(a.operator X&) At least this is the way I think it works. -- ** 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:
<4638jp$ef4@fsgm01.fnal.gov>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<JLM.95Oct12202250@ludo.two-oo-one.fr> <u9burle2pv.fsf@yorick.cygnus.com> <45skdo$cm4@engnews2.Eng.Sun.COM> <45sl3a$coc@engnews2.Eng.Sun.COM> <9510161109.AA08959@slsvgqt.lts.sel.alcatel.de> <damian.813960961@molly.cs.monash.edu.au>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: 18 Oct 1995 17:57:29 GMT Organization: FERMILAB, Batavia, IL Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <4638jp$ef4@fsgm01.fnal.gov> References: <JLM.95Oct12202250@ludo.two-oo-one.fr> <u9burle2pv.fsf@yorick.cygnus.com> <45skdo$cm4@engnews2.Eng.Sun.COM> <45sl3a$coc@engnews2.Eng.Sun.COM> <9510161109.AA08959@slsvgqt.lts.sel.alcatel.de> <damian.813960961@molly.cs.monash.edu.au> Reply-To: sachs@fnal.fnal.gov NNTP-Posting-Host: physics2.berkeley.edu