我有一个 C++ 类,如下所示:
template< template<typename> class ContainerType, typename MemberType>
class MyClass
{
public:
MyClass(ContainerType<MemberType>* volData);
}
我试图用 SWIG 包装。我的 MyClass.i 看起来像:
%module MyClass
%{
#include "SimpleContainer.h"
#include "MyClass.h"
%}
%include "SimpleContainer.h"
%include "MyClass.h"
%template(MyClass_SimpleContainer_Int) MyClass<SimpleContainer, int>;
但是,SWIG 似乎在模板模板参数方面存在问题。编译时它会抱怨错误消息:
MyClassPYTHON_wrap.cxx:30545:3: error: ‘ContainerType’ was not declared in this scope
查看生成代码中的该行,它包含以下行:
ContainerType< int > *arg1 = (ContainerType< int > *) 0 ;
出于某种原因,它逐字使用虚拟模板名称作为类的名称,尽管我已经告诉它这个类的实例化应该有一个 SimpleContainer 的 ContainerType。
有什么办法可以绕过这个错误?我在SWIG 跟踪器中发现了它的提及,但我无法理解上一篇文章中提到的解决方法,而且那个 bug 已经有 4 年的历史了。
我在 openSUSE 11.4 上使用 SWIG 1.3.40 和 GCC 4.5.1