static with Operator overloading in C#

  • Thread starter Thread starter Will Pittenger
  • Start date Start date
W

Will Pittenger

Actually, in C++, you can make operators either static or non-static. That
is what Junaid was referring to. If non-static, the left operand becomes
the "this" pointer. The syntax is similar. In this case it would be as
follows:

public Op operator+(Op AddThis) const

Note that the function is constant. That means that the this pointer is
passed as a const Op*. The function can not change any members. C# does
not support this. I assume that was to eliminate some redundancy. C++
allows static operators so that you allow your class to be the right-hand
operand for types that you have no control over. So if I want to be able to
declare an Op instance as A, I can write my class to allow 3 + A. That
syntax is as follows:

public static Op operator+(int LeftOperand, Op RightOperand)
 
Hi All
i want to ask one question why do we use static keyword with opertor
overloading in C#?,
public static Op operator+(Op a,Op b)

pls reply me as soon as possible
junaidmajeed
 
Back
Top