Re: Constructor Behaviour
Andrew Tomazos wrote:
Please consider the following code...
class A {...}
class B {...}
class C
{
public:
virtual void f();
A a;
C(...)
: a(...)
{ ... }
}
class D : public C
{
public:
virtual void f();
B b;
D(...)
: C(...)
, b(...)
{
...
point1: ;
}
}
void t()
{
D* d = new D();
point2: ...;
}
My question is about the difference in the concrete state of the D
instance between point1 and point2. Namely just before the final
constructor exits (point1) and just after new returns (point2).
Is there any code automatically generated by the compiler to do with
setting up the object (for example to do with RTTI, the vtable,
anything?) that executes between point1 and point2 in the above
example?
Perhaps, but most likely not.
Although nothing of this is actually specified, I expect the code for
setting up the vtable to be inserted just before the opening brace of
the constructor. That way you would get the correct effect for calling a
virtual function from within the constructor for free.
Most of the other 'invisible information' (like RTTI) relates to the
class and not to individual objects so that is probably contained
in/accessible through the vtable.
Technically, the lifetime of the object starts somewhere between point1
and point2 but that will not create any code. It is just a conceptual
notion that tells a programmer what he can expect from an object.
Thanks,
Andrew.
Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://c-faq.com/
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]