c++ 成员访问

本文详细介绍了C++中的成员访问操作符,包括用于值的`.`和用于指针的`->`,以及作用域解析操作符`::`。此外,还提到了指向成员的运算符`.*`和`->*`,它们用于获取指定对象的类成员的值。这些操作符在处理类的对象和指针时起着关键作用。
摘要由CSDN通过智能技术生成

  1.  Member Access Operators: . and ->  

值==》   【.】

地址==》【->】

  • postfix-expression   . member
  (&e)->member  === e.member  (e is a class or struct)


In the first form, postfix-expression represents a value of struct, class, or union type, and name names a member of the specified structure, union, or class. The value of the operation is that of name and is an l-value if postfix-expression is an l-value.


  • postfix-expression -> member

   e->member ====(*e).member  (e is a pointer to a structure or union)


In the second form, postfix-expression represents a pointer to a structure, union, or class, and name names a member of the specified structure, union, or class. The value is that of name and is an l-value. The –> operator dereferences the pointer. Therefore, the expressions e –>member and (* e ).member (where e represents a pointer) yield identical results (except when the operators –> or * are overloaded)



2.Scope Resolution Operator: ::

:: identifier 
class-name :: identifier 
namespace :: identifier

The identifier can be

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值