C++ Overloading
C++ Overloading
Function Overloading
class A {
public:
int add(int i, int j);
int
main (int argc, char **argv) {
int a = 7;
int b = 8;
int c = add(a, b);
return 0;
}
Operator Overloading
class A {
friend ostream &operator<<
(ostream &, const A &);
private:
int m_;
};
Similar to function
overloading
ostream &operator<<
Resolved by signature
Best match is used
Make arithmetic
operators symmetric
As non-member friends
Return result by value
Dont mix base and
derived types in their
parameter lists
a + b * c ^ 2
A A::operator++() // prefix
{++m_; return *this;}
A A::operator++(int) // postfix
{A ret(*this); ++*this; return ret;}