Operator overloading doubt

https://ide.codingblocks.com/s/17901https://ide.codingblocks.com/s/17901

i understand line no 106,107 but have a problrm in 109
in line 109: cout<<v[2];
<< function requires two operands 1 of type ostream and other of type vector class
but here v[2] is of int& type
How it is working correctly

Whenever an operator is overloaded inside a class , it takes a single argument as a parameter because the functions inside the class are called by an object .
Here , if you resolve line no. 109 , You see - operator [ ] is overloaded inside the the class.

So , V[2] is treated as V.operator[ ] (2)

This line returns the value as 1 , which is just printed by the cout.

1 Like

thank you…

Keep asking doubts and keep coding :wink: