Search code examples
c++pointersdereference

C++ - Difference between (*). and ->?


Is there any difference in performance - or otherwise - between:

ptr->a();

and

(*ptr).a(); 

?


Solution

  • Since you are asking for it in the comments. What you are probably looking for can be found in the Standard (5.2.5 Class member access):

    3 If E1 has the type “pointer to class X,” then the expression E1->E2 is converted to the equivalent form (*(E1)).E2;

    The compiler will produce the exact same instructions and it will be just as efficient. Your machine will not know if you wrote "->" or "*.".