c++ arrow operator (->)

From C++ A Beginner’s Guide by Herbert Schildt Chapter8 page 34

The definition as below:

You can access an object either directly (as has been the case in all preceding examples), or by using a pointer to that object. To access a specific element of an object when using a pointer to the object, you must use the arrow operator: –>. It is formed by using the minus sign followed by a greater-than sign. To declare an object pointer, you use the same declaration syntax that you would use to declare a pointer for any other type of data. The next program creates a simple class called P_example, defines an object of that class called ob, and defines a pointer to an object of type P_example called p. It then illustrates how to access ob directly, and how to use a pointer to access it indirectly.

大概意思就是說當你使用了指針來操作一個對象的時候,你在要通過這個指針來訪問對象的成員,就不能再使用 dot operator '.',必須使用 arrow operator '->'.

 

下面也是教程中的示例:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章