[C++-sig] help on abstract class export
Jakub Zytka
kubol at kormoran.net
Fri Apr 29 12:02:29 CEST 2011
On 04/29/11 09:14, zeb wrote:
> mb.free_fun('createWorker').call_policies =
> call_policies.return_value_policy(call_policies.return_pointee_value)
you do not want to have *value* of an abstract class.
> I found that if the IWorker class is not abstract, for example:
> class IWorker {
> public:
> virtual int getData() { return 0; }
> };
>
> Python doesn't report that error, but the result of the following code is
> not expected(I think it should be 100).
You expectancy is wrong. If you keep IWorker by value there will be no dynamic
dispatch.
This is not related to py++, python or boost::python. Its just the same as in
c++. If you wrote a c++ function that takes IWorker parameter by value you'd get
the same behavior.
Basic rule of thumb: if you're dealing with inheritance, do not pass object by
value.
More information about the Cplusplus-sig
mailing list