Possible Duplicate:
C++ – Difference between (*). and ->?
What is the difference between this:
(*ptr).f();
and this:
ptr->f();
in c++ where the ptr is a pointer to C++ class which has a function f?
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.
If
ptris a normal pointer, then both are equivalent.ptr->fis a short-cut to dereference the pointer (equivalent to(*ptr)) and access the member of the dereferenced object (equivalent to.f).If
ptris a class that overloadsoperator->andoperator*, then they will each call different operator overloads, and so could have different behaviour.