why are the bolded methods outside, and what effect has this approach?
Also, why are operator+ and operator- methods followed by const and again, what effect does this bring?
why are the bolded methods outside, and what effect has this approach?
By overloading these operators, you're telling the compiler how it should handle the specified operands when they are used with the operators.
Note that if the same operator was overloaded within a class, the operator that resides within the class has a higher precedence over the globally overloaded operators.
Claimz wrote:
why are operator+ and operator- methods followed by const and again, what effect does this bring?
When const follows a member function definition, it means any non-mutable member cannot be modified by the member function. These are called read-only member functions. These member functions, however, can invoke any read-only member function, and can modify mutable members. In a nutshell, they are member functions that promise not to alter anything.
Edit: C++ doesn't have methods, only member functions.