[C++-sig] Py++ unable to expose an abstract class that inherits from another abstract class

Anand, Kumar kanand at qualcomm.com
Wed Sep 19 01:06:09 CEST 2007


Problem:
-----------
Py++ is unable to expose an abstract class (say Abstract2) that inherits
from another abstract class (say Abstract1), if none of the pure virtual
functions in Abstarct2 are exposed. This is because Py++ always tries to
expose the pure virtual function of base Abstract1 class on the
Abstract2_wrapper class and there seems to be no way to control the
exposure of these base class functions. Look at the example code below
for clarification:

--------------------------Example:
------------------------------------------------------------------------

--------------------C++ code----------------------------

class Abstract1
{
public:
   void virtual func1() =0;
};

class Abstract2 : public Abstract1
{
public:
   void virtual func2() =0;
};

--------------------generate_code.py---------------------

//The following should have caused all member functions on Abstarct2 to
be excluded and
//PY++ should not have generated an Abstract2_wrapper class. However,
this excludes only //the functions on Abstract2 and not the ones
inherited by Abstract1 base class.

mb.class_("Abstract2").member_functions().exclude() 

------------------Generated Py++ code for Abstract2 in
Abstract2.pypp.cpp---------------------

struct Abstract2_wrapper : Abstract2, bp::wrapper< Abstract2 > {

    Abstract2_wrapper()
    : Abstract2()
      , bp::wrapper< Abstract2 >(){
        // null constructor

    }

    virtual void func1(  ){
        bp::override func_func1 = this->get_override( "func1" );
        func_func1(  );
    }
};

void register_Abstract2_class(){

    bp::class_< Abstract2_wrapper, bp::bases< Abstract1 >,
boost::noncopyable >( "Abstract2")
        .def("func1" , bp::pure_virtual( &::Abstract1::func1 ) );

}
------------------------------------------------------------------------
------------------------------------

Abstract2.pypp.cpp does not compile and error message is as follows:

../../../../../../thirdParty/include/boost/python/object/value_holder.hp
p:66: error: cannot declare field
'boost::python::objects::value_holder<Abstract2_wrapper>::m_held' to be
of abstract type 'Abstract2_wrapper'

Thanks
Kumar



More information about the Cplusplus-sig mailing list