On Wed, 14 Apr 2004 12:02:13 +0200, Martin Zimmermann
<Ma***************@hotmail.com> wrote:
Hi.
Is it allowed to dereference 'this' in a constructors initialiser list
to initialize a reference? (for later use)
Yes. You can even do that before the constructor has even started. You
can only use that lvalue to access things that have already been
initialized (such as earlier base classes, earlier member variables
(in class declaration order)).
This is perfectly valid:
Foo* mem = static_cast<Foo*>(malloc(sizeof *mem));
assert(mem);
Foo& f = *mem;
//don't use f until it has been constructed!
new(mem) Foo();
//now you can use f safely.
Tom
--
C++ FAQ:
http://www.parashift.com/c++-faq-lite/
C FAQ:
http://www.eskimo.com/~scs/C-faq/top.html