[問題] 關於運算子多載的問題

看板C_Sharp (C#)作者 (嗨...)時間20年前 (2005/09/24 07:42), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
各位大大好 我寫了一個小程式來練習C#運算子多載的功能 程式如下 using System; public struct Point { public int x, y; public Point(int x, int y) { this.x = x; this.y = y; } //以下省略節省版面 } class A { public static void Main() { Point p1 = new Point(0, 0); Point p2 = new Point(100, 10); Point p3; p3 = p1 + p2; //p3 = p1+p2; Console.WriteLine("p3.X = {0}, p3.Y = {1}", p3.X, p3.Y); } public static Point operator+(Point P1, Point P2)//, Point P2) { Point P; P.x = 1; P.y = 2; return P1; } } 我在編譯這個小程式的時候 一直出現以下的錯誤 One of the parameters of a binary operator must be the containing type 請問這是什麼意思呢??? 請問我的這個小程式裡面有哪裡有錯誤的 因為我想了很久還是想不出來哪裡有問題 請各位高手大大幫幫忙 教一下小弟我 謝謝嚕~~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.168.168.203
文章代碼(AID): #13D9BGWg (C_Sharp)
文章代碼(AID): #13D9BGWg (C_Sharp)