If I have a Foo *foo, I can say foo->bar(). Is it possible to call the operator->() function manually? And if so, how would I pass it bar()?
Does it make a difference if it is Foo foo instead?
Maybe something like foo.operator->(bar)?
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.
Yes, you can. With overloaded
->thefoo->bar()expression is interpreted by the compiler asfoo.operator->()->bar(). And this is exactly how you can call it “manually”:foo.operator->()->bar().If your overloaded
operator ->function is implemented “properly”, i.e. it returns something that also supports operator->then there’s not much point in using the “manual” syntax, since it is doing the same thing as the “non-manual” one.The only case you’d need the “manual” syntax is when your implementation of overloaded
operator ->returns something that does not support another application of->. Anintvalue, for example.