I overloaded the [] operator in my class. Is there a nicer way to call this function from within my class other than (*this)[i]?
I overloaded the [] operator in my class. Is there a nicer way to
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Add function
at(size_t i)and use this function.EDIT: If you actively using stl avoid semantic inconsistence: in
std::vector operator[]does not check if index is valid, butat(..)check and could throwstd::out_of_rangeexception. I think in project with more stl similar behavior will expected from your class.Maybe this name is not best one for this function.