Skip to Content
C++程序设计:原理与实践(基础篇)(原书第2版)
book

C++程序设计:原理与实践(基础篇)(原书第2版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
9h 36m
Chinese
Pearson
Content preview from C++程序设计:原理与实践(基础篇)(原书第2版)

9.4.5 引用当前对象

考虑如下使用Date类的简单代码:

Date::month()是如何知道第一次被调用时应打印d1.m,第二次被调用时应打印d2.m呢?再看一下Date::month(),其声明指出它没有任何参数!那么Date::month()是怎么知道哪个对象在调用它呢?奥妙在这里:每个类成员函数,如Date::month(),都有一个隐式参数,用来识别调用它的对象。因此,在第一次调用中,m会正确地指向d1.m,而在第二次调用中,它指向d2.m。参见12.10节,获得更多使用此隐式参数的内容。

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉

Publisher Resources

ISBN: 9787111562252