Operator Overloading1
Operator Overloading1
Operator Overloading1
d3 = d1 + d2;
d3.addobjects(d1, d2);
d3 = d1.addobjects(d2);
Binary operator
Concat string
Data Conversion
Conversions Between Basic Types
intvar = floatvar;
intvar = static_cast<int>(floatvar);
Show Restraint
Use overloaded operators sparingly, and only
when the usage is obvious. When in doubt,
use a function instead of an overloaded
operator, since a function name can state its
own purpose.
Avoid Ambiguity
Suppose you use both a one-argument constructor
and a conversion operator to perform the
same conversion (time24 to time12, for example).
How will the compiler know which conversion
to use? It wont.
The compiler does not like to be placed in a
situation where it doesnt know what to do, and it
will signal an error. So avoid doing the same
conversion in more than one way.