Article View: comp.std.c++
Article #3204Re: Explicit constructor call vs Temporaries
From: David Sachs
Date: Thu, 01 Feb 1996 22:54
Date: Thu, 01 Feb 1996 22:54
33 lines
1712 bytes
1712 bytes
eddy@siemensrolm.com (eddy Gorsuch) writes:
>Is an explicit call to an object constructor (an unamed object) const or
>not? I have code like the following where I don't care about the parameter
>to X::f(), so I just created an unamed T(). I thought I had tried to compile
>this code and got errors about trying to pass a const object to a non const
>reference parameter. Thinking that the unamed T() counts as a temporary (and
>therefor const) object, I believed that the compiler was right. Now somebody
>tells me that the following code is legal. Is it?
>class T {
> T();
> ~T();
>}
>class X {
> X();
> ~X();
> f(T& t);
>}
>int main() {
> X x;
> x.f(T()); // Compiler complained on this line
>}
Doesn't the statement violate the rule that a temporary may not be
used for a non-const reference parameter of a function?
[ 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://reality.sgi.com/employees/austern_mti/std-c++/policy.html
]
Technical Details
Message-ID:
<4er2vu$jk5@fnnews.fnal.gov>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<4e6plv$idn@eclipse.eng.sc.rolm.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: b91926@fnclub.fnal.gov (David Sachs) Newsgroups: comp.std.c++ Subject: Re: Explicit constructor call vs Temporaries Date: 1 Feb 1996 22:54:37 GMT Organization: Fermi National Accelerator Laboratory, Batavia IL Approved: clamage@eng.sun.com (comp.std.c++) Distribution: usa Message-ID: <4er2vu$jk5@fnnews.fnal.gov> References: <4e6plv$idn@eclipse.eng.sc.rolm.com> Reply-To: sachs@fnal.fnal.gov NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: fnclub.fnal.gov Content-Length: 833 X-Lines: 28 Originator: clamage@taumet