🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: explicit call of constructor

#2630
From: Steve Clamage
Date: Sat, 18 Nov 1995 03:49
30 lines
1396 bytes
Paul Johnson <pjcj@transeda.demon.co.uk> writes:

>I am porting some code that was developed using g++ 2.7.0 on multiple
>platforms, and have come across several explicit calls of
>constructors.  My reading of the ARM and the latest draft to which I
>have access (28th April 95) suggests that this is not correct
>behaviour.

You are correct. It is invalid to attempt to call a constructor
directly (or to take the address of a constructor).

Evidently g++ allows calling a constructor as an extension.

You can usually get the effect of calling a constructor by
using placement-new. That is,
given:
	T* t = ...;
instead of:
	t->T(); // illegal
write:
	new (t) T(); // placement-new
--
Steve Clamage, stephen.clamage@eng.sun.com


---
[ 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: <48jh3m$p3n@engnews1.eng.sun.com>
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt
References: <48if4j$9eb@brian.transeda.demon.co.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: explicit call of constructor
Date: 18 Nov 1995 03:49:38 GMT
Organization: Sun Microsystems Inc., Mountain View, CA
Approved: Matt@Austern
Message-ID: <48jh3m$p3n@engnews1.eng.sun.com>
References: <48if4j$9eb@brian.transeda.demon.co.uk>
NNTP-Posting-Host: austern.hip.berkeley.edu