用于从特殊模板类型继承的类的Swig包装器会导致缺少方法

问题描述 投票:0回答:1

我正在使用Swig 1.4.1为C#项目包装一些C ++代码。考虑以下代码位于一个文件Foo.h

中。
#ifndef __Foo__
#define __Foo__

namespace Ogre
{
    template<int foo, typename T> class FooBase
    {
    public:

        int getFooBase() const
        {
            return 1;
        }
    };

    struct FooSpecialized : public FooBase<4, double>
    {
        int getFooSpecialized() const
        {
            return 2;
        }
    };

    class FooImpl : public FooSpecialized
    {
    public:
        int getFooImpl() const
        {
            return 3;
        }
    };
}

#endif

为此,我在Swig接口文件中使用以下内容。

%include "Foo.h"

因此,我可以访问方法getFooSpecialized()getFooImpl()。但是getFooBase()丢失。

编译Swig接口文件时得到无警告。>>

通过查看生成的C#文件可以很容易看出。有一个文件FooSpecialized.cs

其中包含
public class FooSpecialized : global::System.IDisposable {
  ...

  public int getFooFooSpecialized() {
    int ret = OgrePINVOKE.FooSpecialized_getFooFooSpecialized(swigCPtr);
    if (OgrePINVOKE.SWIGPendingException.Pending) throw OgrePINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }
}

FooImpl.cs

,其中包含
public class FooImpl : FooSpecialized {
  ...

  public int getFooImpl() {
    int ret = OgrePINVOKE.FooImpl_getFooImpl(swigCPtr);
    if (OgrePINVOKE.SWIGPendingException.Pending) throw OgrePINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }
}

到目前为止,我尝试过%rename%template,但是它不起作用。我还阅读了有关拆分文件的信息,但这对我来说是没有选择的,因为它是我正在使用的第三方组件。

我正在使用Swig 1.4.1为C#项目包装一些C ++代码。考虑以下代码位于一个文件Foo.h中。 #ifndef __Foo__ #define __Foo__名称空间Ogre {template

c++ swig
1个回答
1
投票

关键是%template的使用和位置。按原样使用Foo.h,以下test.i文件有效:

© www.soinside.com 2019 - 2024. All rights reserved.