[C++-sig] How to wrap reference to abstract base class to get C++ polymorphism

Nicolas Colombe nicolas.colombe at gmail.com
Mon May 24 10:42:11 CEST 2010


2010/5/20 Kun Hong <kun.hong at uqconnect.edu.au>

>
>
> class B
> {
> public:
>        virtual const char *getName() const = 0;
> };
>
> BOOST_PYTHON_MODULE(Test)
> {
>
>        class_<B, boost::noncopyable>
>            ("B", no_init)
>                .def("getName", pure_virtual(&B::getName))
>        ;
>
>        def("getB", &getB,
> return_value_policy<reference_existing_object>());
> }
>
> When you expose your method getName, expose it like a classic method,
without the pure_virtual. The C++ will perform the virtual call itself.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20100524/288d6993/attachment.html>


More information about the Cplusplus-sig mailing list