How to call an overloaded operator in another member function of a class in C++ ?
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.
Assuming it’s overloaded as a member, you generally use
(*this)operator<parameter(s)>, so if a class has an overload ofoperator[]that takes, say, an int parameter (e.g.,T &operator[](int index);), another member function can invoke it with(*this)[2].If it’s overloaded as a free function, you do pretty much the same sort of thing. For example, assuming you had a free function like:
You could invoke it from a member function like:
Probably not useful in quite this simplistic of a case, but still shows the general idea.