🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Explicit constructor call vs Temporaries

#3146
From: eddy Gorsuch
Date: Thu, 25 Jan 1996 16:12
34 lines
1643 bytes
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
}

eddy
-- 
ed.dy \'ed-e-\ n [ME (Sc dial.) ydy, prob. fr. ON itha; akin to OHG ith- 
   again], L et and 1a: a current of water or air running contrary to the main 
   current; esp)X : a small whirlpool 1b: a substance moving similarly  2: a 
   contrary or circular current  - eddy vb

[ 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: <4e6plv$idn@eclipse.eng.sc.rolm.com>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: eddy@siemensrolm.com (eddy Gorsuch)
Newsgroups: comp.std.c++
Subject: Explicit constructor call vs Temporaries
Date: 25 Jan 1996 16:12:06 GMT
Organization: Siemens Rolm Communications Inc.
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <4e6plv$idn@eclipse.eng.sc.rolm.com>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
Content-Length: 929
X-Lines: 30
Originator: clamage@taumet