[問題] 關於運算子多載的問題
各位大大好
我寫了一個小程式來練習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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章