2011-02-13 30 views
0

可能重复:
What is the difference between the dot (.) operator and -> in C++?C++成员选择算

C++具有以下部件选择算子:.->

主要是它们之间的区别是什么?

谢谢。

+2

此问题已被问到这里 - http://stackoverflow.com/questions/1238613/what-is-the-difference-between-the-dot-operator-and-in-c – 2011-02-13 12:25:00

+0

这个问题也是一个问题重复的http://stackoverflow.com/questions/221346/what-is-the-arrow-operator-synonym-for-in-c – 2011-02-13 12:29:18

回答

1

.与非指针一起使用,而->与指针一起使用来访问成员!

Sample s; 
Sample *pS = new Sample(); 

s.f() ; //call function using non-pointer object 
pS->f(); //call the same function, using pointer to object 

.不能被重载,而->可以被重载。

1

pointer2object->member() 等于 (*pointer2object).member() 和用于更舒适制成,如我想。