ptr-> hello(); / * VERSUS * /(* ptr).hello(); [英] ptr->hello(); /* VERSUS */ (*ptr).hello();

查看:112
本文介绍了ptr-> hello(); / * VERSUS * /(* ptr).hello();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学习C ++指针,并且 - > 操作符对我来说很奇怪。而不是
ptr-> hello(); 可以写(* ptr).hello();

I was learning about C++ pointers and the -> operator seemed strange to me. Instead of ptr->hello(); one could write (*ptr).hello(); because it also seems to work, so I thought the former is just a more convenient way.

是这种情况还是有什么区别?

Is that the case or is there any difference?

推荐答案

- >运算符只是语法糖,因为(* ptr).hello )是要输入的PITA。对于在ASM级别生成的指令,没有区别。事实上,在一些语言(D的想法),编译器根据类型计算一切。如果你做 ptr.hello(),它只是工作,因为编译器知道ptr是一个指针,没有hello()属性,所以你必须是(* ptr).hello()

The -> operator is just syntactic sugar because (*ptr).hello() is a PITA to type. In terms of the instructions generated at the ASM level, there's no difference. In fact, in some languages (D comes to mind), the compiler figures everything out based on type. If you do ptr.hello(), it just works, because the compiler knows that ptr is a pointer and doesn't have a hello() property, so you must mean (*ptr).hello().

这篇关于ptr-> hello(); / * VERSUS * /(* ptr).hello();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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