Topic: explicit call of constructor
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/11/18 Raw View
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. ]