Computer Fundamentals |
|---|
| What is computer? |
| Software |
| Hardware |
| Operating System |
Programming Language |
| Java |
| C# |
| Python |
| Visual Basic |
| Jscript.NET |
Web Development
|
| HTML |
| ASP |
| PHP |
| JavaScript |
| VBScript |
.NET |
| .NET Micrsoft |
| ASP.NET |
| .NET Mobile |
Forum |
| VB/VB.NET |
| ASP/ASP.NET |
| VBScript |
| JavaScript |
| Topic: C++-Language Operator Overloading Operator overloading is the ability to tell the compiler how to perform a certain operation when its corresponding operator is used on one or more variables. For example, the compiler acts differently with regards to the subtraction operator “-“ depending on how the operator is being used. When it is placed on the left of a numeric value such as -48, the compiler considers the number a negative value. When used between two integral values, such as 80-712, the compiler applies the subtraction operation. When used between an integer and a double-precision number, such as 558-9.27, the compiler subtracts the left number from the right number; the operation produces a double-precision number. When the - symbol is doubled and placed on one side of a variable, such as --Variable or Variable--, the value of the variable needs to be decremented; in other words, the value 1 shall be subtracted from it. All of these operations work because the subtraction operator “-” has been reconfigured in various classes to act appropriately. C++ incorporates the option to use language standard operators between classes in addition to between fundamental types. For example: int a, b, c; is perfectly valid, since the different variables of the addition are
all fundamental types. Nevertheless, is not so obvious that we can perform
the following operation (in fact it is incorrect): + - * / = < > += -= *= /= << >> To overload an operator we only need to write a class member function
whose name is operator followed by the operator sign that we want to
overload, following this prototype:
|
|