|
Boost Users : |
Subject: Re: [Boost-users] How shared_from_this() work when it inherited from more than one time
From: R. P. Janaka (rpjanaka_at_[hidden])
Date: 2009-08-10 00:54:08
Since you're not calling shared_from_this() in A, I suggest you remove
enable_shared_from_this<A> altogether.
But in my case there is no option like this (Class A is a base library
class). So I have to do this.
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.
I did the above to avoid the ambiguous call error
So how can I specify that i am calling the shared_from_this() in class
B....?
On Mon, Aug 10, 2009 at 4:33 AM, Christian Holmquist
<c.holmquist_at_[hidden]>wrote:
>
> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
-- Regards, R. P. Janaka
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