所以我尝试创建std_complex.i(因为开箱即用的C#SWIG库中没有这样的东西)。这是我试过的:
%{
#include <complex>
%}
namespace std {
template<class T>
class complex {
public:
complex(T r, T i);
complex(const complex<T> & other);
T imag();
T real();
%rename(Add) operator+=;
%rename(Substract) operator-=;
%rename(Multiply) operator*=;
%rename(Divide) operator/=;
complex<T>& operator+= (const complex<T>& rhs);
complex<T>& operator-= (const complex<T>& rhs);
complex<T>& operator*= (const complex<T>& rhs);
complex<T>& operator/= (const complex<T>& rhs);
};
}
%template(Complex) std::complex<double>;
生成的包装器确实执行了类成员操作,但我不知道如何转发==
运算符,例如+
或operator+
。那么如何在SWIG C#中转发非成员函数?
例如,这个template<class T> complex<T> operator+(const complex<T>& lhs, const complex<T>& rhs);
template<class T> complex<T> operator+(const complex<T>& lhs, const T& val);
template<class T> complex<T> operator+(const T& val, const complex<T>& rhs);
:
{{1}}