✏️

Operator Overloading

Tags
Expression
As member function
As non-member function
Example
@a
(a).operator@ ( )
operator@ (a)
!std::cin calls std::cin.operator!()
a@b
(a).operator@ (b)
operator@ (a, b)
std::cout << 42 calls std::cout.operator<<(42)
a=b
(a).operator= (b)
cannot be non-member
Given std::string s;, s = "abc"; calls s.operator=("abc")
a(b...)
(a).operator()(b...)
cannot be non-member
Given std::random_device r;, auto n = r(); calls r.operator()()
a[b...]
(a).operator[](b...)
cannot be non-member
Given std::map<int, int> m;, m[1] = 2; calls m.operator[](1)
a->
(a).operator->( )
cannot be non-member
Given std::unique_ptr<S> p;, p->bar() calls p.operator->()
a@
(a).operator@ (0)
operator@ (a, 0)
Given std::vector<int>::iterator i;, i++ calls i.operator++(0)
In this table, @ is a placeholder representing all matching operators: all prefix operators in @a, all postfix operators other than -> in a@, all infix operators other than = in a@b.