Search code examples
c++operator-overloadingfriend-function

Which C++ operators can not be overloaded without friend function?


Which C++ operators can not be overloaded at all without friend function?


Solution

  • The operators where the left-hand-side operand is not the class itself. For example cout << somtething can be achieved via defining a std::ostream& operator<<(std::ostream& lhs, Something const & rhs); function, and marking them as friend inside the class.

    EDIT: Friending is not needed, ever. But it can make things simpler.