使用SWIG封装模板模板参数类 [英] Wrapping template template parameter class with SWIG

查看:184
本文介绍了使用SWIG封装模板模板参数类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似下面的C ++类:

I have a C++ class like the following:

template< template<typename> class ContainerType, typename MemberType>
class MyClass
{
  public:
    MyClass(ContainerType<MemberType>* volData);
}

My MyClass.i如下所示:

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>;

但是,SWIG似乎有模板模板参数的问题。当编译它时出现错误信息:

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 ;

由于某种原因,它使用伪模板名称作为类的名称, ve告诉它这个类的实例化应该有一个Container类型的SimpleContainer。

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.

有没有什么办法,我可以绕过这个bug?我发现在 SWIG跟踪器中提到它,但我无法

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.

我在openSUSE 11.4上使用SWIG 1.3.40和GCC 4.5.1。 / p>

I'm using SWIG 1.3.40 and GCC 4.5.1 on openSUSE 11.4

推荐答案

你的C ++头文件的第一行看起来很奇怪。尝试以下操作:

The first line of your C++ header looks strange to me. Try the following:

template<class ContainerType, typename MemberType>

这篇关于使用SWIG封装模板模板参数类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆