Raf256 <e7**********@inews.gazeta.pl> Friday 23 of June 2006 22:59
I have base template class A<B>, and son class B.
Inside A<B> constrcutor, can I access a pointer to B, from "this"?
like
A<B>::A() : pointerToB(static_cast<B*>this) { }
I will use the pointer.
Can I use the pointer in A<B> constructor?
In my friends opinion:
[23:02] <pfeilspitze> raf256: in the base class's constructor, the derived
class is not yet constructed, so you cannot use it.
[23:03] <raf256> pfeilspitze: ok. But, can I hold a pointer to derived
class, and use it later (after all CTORs are done), or will the pointer
address change?
[23:03] <pfeilspitze> holding a pointer is safe
[23:03] <pfeilspitze> it's like it's an incomplete type, raf256
So we are correct, I can acquire a pointer to B inside A<B>::A<B>(), and I
can use it - only I have to NOT use it inside the constructor?
--
Rafa³ Maj
Raf256 - Raf256.org - C++ (comming soon)