|
Boost : |
From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-10-09 15:11:33
--- Rainer Deyke <rainerd_at_[hidden]> wrote:
> E. Gladyshev wrote:
> > --- Rainer Deyke <rainerd_at_[hidden]> wrote:
> >
> >> I can think of at least one degenerate case where your trick fails.
> >>
> >> class A;
> >>
> >> A* the_A = 0;
> >>
> >> class A {
> >> A() { the_A = this; }
> >> ~A() { the_A = 0; }
> >> };
> >>
> >> class B {
> >> B() { if (the_A) do_something_with(the_A); }
> >> };
> >>
> >> variant<A, B> v(A());
> >> v = B();
> >>
> >
> > It'll fail as soon as you use placement 'new'
> > regadless of this trick.
>
> Does "it" above refer to your code (variant::operator=) or my code (class A
> and B above)?
Sorry, I meant your code.
The problem is that B's default constructor breaks
in this particular.
When your write v = B(, boost::variant use
placement 'new' (as it should).
The placement 'new' will render the the_A invalid
(in a sense it not pointing to A any more),
the B() constructor tries to use the invalid the_A.
It is where it break. It has nothing to do with
the trick.
Eugene
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk