【问题标题】:Wrapping template template parameter class with SWIG使用 SWIG 包装模板模板参数类
【发布时间】:2011-09-07 02:15:49
【问题描述】:

我有一个像下面这样的 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 tracker 中发现了它的提及,但我无法理解上一篇文章中提到的解决方法,而且该错误已经存在 4 年了。

我在 openSUSE 11.4 上使用 SWIG 1.3.40 和 GCC 4.5.1

【问题讨论】:

  • 我已经升级到 SWIG 2.0.3 并且错误仍然存​​在。

标签: c++ templates swig template-templates


【解决方案1】:

C++ 标头的第一行对我来说看起来很奇怪。请尝试以下操作:

template<class ContainerType, typename MemberType>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-20
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多