Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Section A.11. Operator overloading

A.11. Operator overloading

Operator overloading enables you to define how instances of your class should behave when they’re used in expressions. For example, if you want to be able to add instances together, you can define operator +:

class Magnitude {
    //...
    public static operator +(Magnitude a, Magnitude b) {
        return Magnitude(a.size + b.size);
    }
}


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial