Tomas wrote:
> class Base
> {
> public:
>
> int* const p;
>
> Base(int* const x) : p(x) {}
> };
>
> class Derived : public Base
> {
> public:
>
> int monkey[8];
>
> Derived() : Base(monkey) {}
> };
> Is this okay? Can I be certain that "monkey" will have been created before
> the constructor of the Base class is called?
Construction happens from top to bottom. Base will fully construct, with the
address where monkey will be, before monkey constructs.
However, monkey already has storage, so it can point to it.
New question; how defined is this?
Base(int* x) : p(x)
{
*p;
p[3] = 42;
int whatever = p[4];
}
All those lines deference valid storage containing an unconstructed int.
Ints have trivial constructors, but I thought I heard that all three of
those lines generate technically undefined behavior.
They will probably "work". Don't do any of this in professional code.
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!