Re: Constructor Behaviour
On Apr 21, 9:25 am, Andrew Tomazos <and...@tomazos.com> wrote:
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?
Note that vtable is an implemenation detail (a C++ implementation
needs not use such a mechanism).
As far as Standard goes, during evaluation of "new D", at point1, all
virtual functions should resolve to their final overriders in D, and
typeof(*this) should be typeof(D). In that sense, nothing changes
between point1 and point2.
The only difference (which isn't in the object representation) in a
similar case is that, if, past point1 but before the end of
constructor body, an exception gets thrown (for example, if destructor
of any local object declared in D() throws), ~D() will not be called.
At point2 - if d was an object with automatic storage, or a smart
pointer, rather than a raw one - there is a guarantee that ~D() will
be called.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]