C ++ - (*)之间的差异。和 - >? [英] C++ - Difference between (*). and ->?

查看:183
本文介绍了C ++ - (*)之间的差异。和 - >?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

性能之间或之间有任何差异:

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

ptr->a();

(*ptr).a(); 

推荐答案

因为你在评论中要求它。您可能正在寻找的内容可以在标准(5.2.5类成员访问)中找到:

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如果E1具有类型指向类
X的指针,那么表达式E1-> E2是
转换为等价形式
(*(E1))E2;

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 "*.".

这篇关于C ++ - (*)之间的差异。和 - >?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆