看了swig的文档,还是没有明白c#如何重载operator, 想知道下面的代码:
bool operator==(const Vector3& v) const; 
bool operator!=(const Vector3& v) const;
在swig的.i文件中如何处理.
swig的官方文档中提到了用%rename,请问如何写呢

解决方案 »

  1.   

    swig的文档是什么东西啊?给你个书上的运算符重载例题using System;
    class UsingOperOverload                       //操作符重载
    {
        static void Main()
        {
            clsRectangle myRectangle=new clsRectangle();
            myRectangle.GetArea(100,50);
            Console.WriteLine("以下输出宽等于100,长等于50的长方形面积:\n");
            Console.WriteLine(myRectangle .intArea);
            Console.WriteLine("\n运用重载运算符+将长方形面积加10");
            myRectangle++;
            Console.WriteLine("\n以下重新输出长方形面积:\n");
            Console.WriteLine(myRectangle .intArea);
            Console.ReadLine();
        }
    }
    class clsRectangle
    {
        int intWidth;
        int intLength;
        public int intArea;
        public clsRectangle()
        {
        }
        public void GetArea(int x, int y)
        {
            intWidth = x; 
            intLength = y;
            intArea = intWidth * intLength;
        }
        private void IncreArea()
        {
            intArea += 10;
        }
        public static clsRectangle operator ++(clsRectangle opRectangle) //++操作原来相当与x86里的INC,现在被重载了
        {
            clsRectangle myRectangle=new clsRectangle ();
            myRectangle = opRectangle;
            myRectangle.IncreArea();
            return myRectangle;    }
    }