我正在使用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
关键是%template
的使用和位置。按原样使用Foo.h
,以下test.i
文件有效: