Re: this newsroup
"Paul" <pchristor@yahoo.co.uk> wrote...
"Liviu" <lab2k1@gmail.c0m> wrote...
"Paul" <pchristor@yahoo.co.uk> wrote...
"Liviu" <lab2k1@gmail.c0m> wrote...
There is no nsmf call on 'this' after the destructor.
For your convenience, here is the abridged core code again.
The code below is totally different from your original code.
Huh?? Are you being deceitful on some purpose, or just forgetful?
Lookup your post where you asked "Please can you clarify what exactly
you are trying to do". That was your direct reply to the code I posted,
so you can't even pretend that you didn't see it.
Now take the A::f from my code posted there, drop the comment, cout,
and assert lines - which affect neither the point nor the mechanics of
the exercise. What's left is the _exact_ code I posted now.
void A::f(int n)
{
if(n)
{
this->~A();
A *that = (n % 3) ? new(this) A : new(this) B;
that->f(n - 1);
If 'that' is a B, a completely different function is called.
}
}
What is this supposed to prove? This certainly isn't recurrence.
Go back to my original post with the code, or any number of posts since
then where I re-copied the output lines. Focus on the first two lines:
|| A::f, object 1, this = 0012FF54
|| A::f, object 2, this = 0012FF54
The same function A::f calls itself with the same 'this' pointer. See?
And what happens if a new B is allocated?
Then B::f is called virtually, as shown on line #3 of the same output.
|| B::f, object 1, this = 0012FF54
Suddenly you have a vtable scenario. The original obect was stored
on the stack [...]
Huh?? The original object was created on the heap. It can't get much
more clear than this:
|| void *p = malloc(max(sizeof(A), sizeof(B)));
|| A *a = new(p) A;
Liviu