Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operator overload for [] operator

Why would you need to overload the [] operator? I have never come across a practical scenario where this was necessary. Can somebody tell me a practical use case for this.

like image 245
ckv Avatar asked Jun 24 '26 10:06

ckv


1 Answers

Err.. std::vector<t>, std::basic_string<t>, std::map<k, v>, and std::deque<t> ?

I used this for a class representing a registry key, where operator[] returned an object representing a registry value with the string between []s.

See also, the Spirit Parser Framework, which uses [] for semantic actions.

like image 80
Billy ONeal Avatar answered Jun 26 '26 02:06

Billy ONeal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!