使用 SWIG 包装模板模板参数类
我有一个如下所示的 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 ;
出于某种原因,它逐字使用虚拟模板名称作为类的名称,即使我已经告诉它此实例化该类的 ContainerType 应该为 SimpleContainer。
有什么办法可以解决这个错误吗?我在 SWIG 跟踪器 但我无法理解上一篇文章中提到的解决方法,而且该错误已经存在 4 年了。
我在 openSUSE 11.4 上使用 SWIG 1.3.40 和 GCC 4.5.1
I have a C++ class like the following:
template< template<typename> class ContainerType, typename MemberType>
class MyClass
{
public:
MyClass(ContainerType<MemberType>* volData);
}
which I am trying to wrap with SWIG. My MyClass.i looks like:
%module MyClass
%{
#include "SimpleContainer.h"
#include "MyClass.h"
%}
%include "SimpleContainer.h"
%include "MyClass.h"
%template(MyClass_SimpleContainer_Int) MyClass<SimpleContainer, int>;
However, SWIG seems to have problems with the template template parameter. When compiling it complains with the error message:
MyClassPYTHON_wrap.cxx:30545:3: error: ‘ContainerType’ was not declared in this scope
Looking at that line in the generated code, it contains the line:
ContainerType< int > *arg1 = (ContainerType< int > *) 0 ;
For some reason it's using verbatim the dummy template name as the name of the class, even though I've told it that this instantiation of the class should have a ContainterType of SimpleContainer.
Is there any way that I can get around this bug? I found mention of it in the SWIG tracker but I couldn't understand the workaround mentioned in the last post and also that bug is 4 years old.
I'm using SWIG 1.3.40 and GCC 4.5.1 on openSUSE 11.4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 C++ 头文件的第一行对我来说看起来很奇怪。请尝试以下操作:
The first line of your C++ header looks strange to me. Try the following: