![]() ![]() ![]() For example, it knows how to add two long s or how to divide one double by another double, and can generate the appropriate intermediate language code. With what you've learned so far, operators like + and * have been strictly for the predefined data types, and for good reason: the compiler automatically knows what all the common operators mean for those data types. The result would probably look a bit messy, like this: Matrix d = c.Multiply(a.Add(b)) If we were coding in a language that didn't have operator overloading, we'd have presumably have to define methods to perform those operations. So it's quite plausible that you'd want to write code like this: Matrix a, b, c // assume a, b and c have been initialized Matrix d = c * (a + b) īy overloading the operators, you can effectively tell the compiler what + and * does to a Matrix, allowing you to write code like the above. Now in the world of math, matrices can be added together and multiplied, just like numbers. Suppose for example you had defined a class that represents a mathematical matrix. ![]() Often you need to do things like adding quantities together, multiplying them, or performing logical operations such as comparing objects. The point of operator overloading is that you don't always just want to call methods or properties on class instances. C++ developers will probably prefer to skip straight to the main example. However, since the concept will be new to both Java and VB developers, we'll explain the concept of it here. Operator overloading is something that will be familiar to C++ developers. We start by discussing operator overloading in this section. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
February 2023
Categories |