c++ - SWIG issue with pointers -


i have problem wrapping member of c++ class swig.

i have class has method returns map<int, postlib::nastran::element>.

the class postlib::nastran::element in interface file is:

class element { public:     element(void) ;     element( const element &in) ;     ~element(void) ;      // data manipulation     %feature("docstring", "gettype()->int\n\treturns id corresponding type of fe element") gettype;     int gettype(void) const ;     std::string  gettypename(void) const ;     int getnbrnodes(void) const ;     int getnode(int index) const ;      /*     %extend {             std::set<int>  getnodes(void) {             const std::set<int> *silist;              silist = &$self->getnodes();             return *silist;             }     }*/ } ; //class element 

my method looks this:

pyobject * getels(void) {     std::map<int, postlib::nastran::element> els = $self->getelements();     std::map<int, postlib::nastran::element>::iterator it;     //pyobject * result = pydict_new();     pyobject * result = pylist_new(els.size());     (std::map<int, postlib::nastran::element>::iterator it=els.begin(); it!=els.end(); ++it) {         pyobject * k = py_buildvalue("i", (it->first)-1);         postlib::nastran::element * e = &(it->second);         //pyobject * v = py_buildvalue("i", &(it->second));         pyobject *v = swig_newpointerobj((void *)e, swigtype_p_postlib__nastran__element, swig_pointer_own);         //pydict_setitem(result, k, v);         pylist_setitem(result, (it->first)-1, v );         std::cout << typeid(&it->second).name()  << std::endl;     }     return result; } 

when invoke method gettype() on element instances python following error message:

pure virtual method called 

the element class inherits more generic element class defines gettype virtual.

any ideas?

thanks in advance.

i have never used swig python language, have came across error when making java wrapper, hope it's same.

this error raises when python call gettype member method because c++ pure virtual method, means has no implementation , intended overwritten/implemented subclasses. python invoking not implemented method.

does postlib::nastran::element declare method virtual , equal 0, like:

virtual int gettype(void) const = 0; 

if pure virtual , in .i file haven't declare way. when swig encounters class pure virtual methods not generate constructors type (because can't instantiate lacks implementation).

if method pure virtual class in intended subclassed. swig can using directors feature, can extend c++ class python , use it.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -