带指针的SWIG问题 我用SWIG包装C++类的成员有问题。
我有一个类,它有一个返回带指针的SWIG问题 我用SWIG包装C++类的成员有问题。,c++,pointers,map,instance,swig,C++,Pointers,Map,Instance,Swig,我有一个类,它有一个返回map的方法 接口文件中的类postLib::nastran::element为: class element { public: element(void) ; element( const element &in) ; ~element(void) ; // data manipulation %feature("docstring", "getType()->int\n\tReturns an id corre
map
的方法
接口文件中的类postLib::nastran::element
为:
class element {
public:
element(void) ;
element( const element &in) ;
~element(void) ;
// data manipulation
%feature("docstring", "getType()->int\n\tReturns an id corresponding to the 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
元素类继承自另一个更通用的元素类,该类将getType定义为virtual
有什么想法吗
提前感谢。我从未将swig与Python语言一起使用过,但我在制作Java包装器时遇到了这个错误,希望是相同的
此错误从Python调用GETType成员方法时引发,因为它是C++纯虚方法,这意味着它没有实现,并且打算被子类覆盖/实现。因此,基本上从Python调用的是一个未实现的方法
postLib::nastran::element
是否将该方法声明为virtual并等于0,类似于:
virtual int getType(void) const = 0;
如果是,那么它是纯虚拟的,并且在您的.i文件中没有这样声明。当SWIG遇到具有纯虚拟方法的类时,它不会为该类型生成构造函数(因为您无法实例化缺少实现的对象)
如果该方法是纯虚拟的,那么该类将被子类化。SWIG可以使用<代码>导演< /C>功能,这样你就可以从Python扩展C++类,并使用它。
pure virtual method called
virtual int getType(void) const = 0;