[C++-sig] Wrapping shared_ptr of virtual classes
Will Lee
lee.will at gmail.com
Tue Aug 8 23:48:38 CEST 2006
I have seen this post (
http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2262721) a while a go
but I couldn't find the response that solves this problem. Essentially, I
couldn't find a way to wrap an abstract class that is being returned as a
shared_ptr. For the following scenario:
class A has virtual method f
class B inherits from A that implements f
class F that has a static method: shared_ptr<A> getInstance()
Essentially I want to call F.getInstance().f() in python, which will call
B::f
All the documentation points to creating a wrapper class, so I have done so:
struct AWrapper : A, wrapper<A>
(would wrap function "f" that uses this->get_override() call to call the
overridden function)
My question is, like what is in the post, how do I declare class A?
I don't think I can declare the AWrapper, since F.getInstance() returns
shared_ptr<A> and not shared_ptr<AWrapper>:
class_<AWrapper, shared_ptr<AWrapper>, boost::noncopyable>...
I don't think I can declare with A either, since how can I tie the wrapper
function calls?
class_<A, shared_ptr<A>, boost::noncopyable>
Then this just gets me confused in what it would do (I got a convert error
saying that there is no to_python converter found):
class_<A, AWrapper, shared_ptr<A>, boost::noncopyable>
...
Your help is greatly appreciated.
Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060808/d9685b72/attachment.htm>
More information about the Cplusplus-sig
mailing list