Please explain the syntax and working of the code given below which we have written while designing our own vector class:
void operator[] (const int i)
{
return arr[i];
}
I couldn’t understand anything in the above code, please explain it in detail
Designing our own Vector
Hey @Tiwary725
So this code says that if you have a vector say VEC
and you use operator [ ] with VEC
and the data inside [ ] is i
Then this function should return VEC[ i ]
Which means ith element in the vector
If your doubt is resolved please close it
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.