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@gmail.com> 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@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users



--
Regards,
R. P. Janaka