使用this->是否有任何开销?访问会员? [英] Is there any overhead using this-> for accessing a member?

查看:58
本文介绍了使用this->是否有任何开销?访问会员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

访问某个类的成员时,我可以使用例如:

  this-> myVar = 10 

或者我可以写:

  myVar = 10 

我喜欢使用 this-> ,因为它显式声明了该变量是该类的成员,但是与仅使用变量名本身相比,它是否会引起任何开销?/p>

作为替代方案,我可以在var中添加一个唯一的前缀,例如 _TmyVar ,但是我已经使用了 this-> 很长时间了,所以我只是想知道.

解决方案

没有任何开销.编译器将为两个版本生成完全相同的代码.

When accessing a member of some class, I can use e.g.:

this->myVar = 10 

or I can just write:

myVar = 10

I like to use this-> because it explicitly declares that the variable is a member of this class, but does it cause any overhead in comparison to just using the variable name by itself?

As an alternative I could maybe add a unique prefix to the vars, such as _TmyVar, but I've been using this-> for a long time so I just wondered.

解决方案

There is no overhead. The compiler will generate the exact same code for both versions.

这篇关于使用this->是否有任何开销?访问会员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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