overloading operators << >>
https://www.sololearn.com/en/compiler-playground/cLxlhVfBzs32 I wrote a 2d vector class such that it has the operations += *= - *= ++v ++v , I found how the << >> can be written yet still trying to understand the code for this I assume I am allowing the function itself to access my class member v so I am befriending the operator itself not the ostream or istream class itself the type I am getting is a reference to an object of the class ostream ? is cout a named object inside the library ? std::cout<<v; such that I am inserting the result to the output stream object using << friend std::ostream& operator<<(std::ostream& s, const Vector2D& v) { return s << v[0] << ' ' << v[1]; } friend std::istream& operator>>(std::istream& s, Vector2D& v) { return s >> v[0] >> v[1]; }