[C++-sig] help on abstract class export
Roman Yakovenko
roman.yakovenko at gmail.com
Fri Apr 29 11:07:13 CEST 2011
On Fri, Apr 29, 2011 at 10:14 AM, zeb <zebbey at gmail.com> wrote:
> Hi, I'm trying to export the following code to python, but failed. Please
> help me!
> Here is the code:
> --------------
> c++ code:
> --------------
> class IWorker {
> public:
> virtual int getData() = 0;
> };
>
> class Worker : public IWorker {
> public:
> int getData() {
> return 100;
> }
> };
>
> extern "C" {
> IWorker* createWorker();
> }
>
> --------------
> py++ code:
> --------------
> mb.free_fun('createWorker').call_policies =
> call_policies.return_value_policy(call_policies.return_pointee_value)
If createWorker is implemented as "return new Worker(....);", then you
should use "return_value_policy<manage_new_object>"
( http://www.boost.org/doc/libs/1_46_1/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies
)
If you change the function return type to "std::auto_ptr<...>" then
you don't need to specify the call policies.
HTH
More information about the Cplusplus-sig
mailing list