Boost logo

Boost Users :

Subject: Re: [Boost-users] How shared_from_this() work when it inherited from more than one time
From: Christian Holmquist (c.holmquist_at_[hidden])
Date: 2009-08-09 19:03:10


> void f(void)
> {
> cout << "this is working " <<
> boost::enable_shared_from_this<B>::shared_from_this() << endl;
> }
> };
>

You create an empty enable_shared_from_this<B>, then call shared_from_this()
on that one which is of course empty. Intended usage is

class B : public A, public boost::enable_shared_from_this<B>
{
public:
B() {}
virtual ~B() {}

void f(void)
{
cout << "this is working " << shared_from_this() << endl;
                                          // ^^^^^^^^^^^^^^^^^^^^^^
}
};

This is not the only error though, Since you're deriving from
enable_shared_from_this two times, the above will give an ambiguous call
error (did you mean enable_shared_from_this<A> or
enable_shared_from_this<B>).

Since you're not calling shared_from_this() in A, I suggest you remove
enable_shared_from_this<A> altogether.

/ christian

> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net