Chinaunix首页 | 论坛 | 博客
  • 博客访问: 475457
  • 博文数量: 111
  • 博客积分: 3146
  • 博客等级: 中校
  • 技术积分: 939
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-07 11:23
个人简介

Nathing

文章分类

全部博文(111)

文章存档

2016年(2)

2015年(1)

2014年(31)

2012年(2)

2011年(9)

2010年(36)

2009年(30)

我的朋友

分类: C/C++

2009-07-07 13:59:25

每个成员函数都有一个额外的、隐含的形参 this.
 
total.same_isbn(trans);
 
当名为 total 的对象调用same_isbn 时,这个对象也传递给了函数.而 same_isbn 函数使用 isbn 时,就隐式地使用了调用该函数的对象的 isbn 成员.这个函数调用的效果是比较 total.isbntrans.isbn 两个值.
编译器这样重写这个函数调用:
Sales_item::same_isbn(&total, trans);
this 指针的使用

成员函数中,不必显式地使用 this 指针来访问被调用函数所属对象的成员。对这个类的成员的任何没有前缀的引用,都被假定为通过指针 this 实现的引用:

     bool same_isbn(const Sales_item &rhs) const
         { return isbn == rhs.isbn; }

在这个函数中 isbn 的用法与 this->units_soldthis->revenue 的用法一样。

bool same_isbn(const Sales_item &rhs) const {return this->isbn == rhs.isbn; }

 

构造函数是特殊的成员函数

 

构造函数的形参指定了创建类类型对象时使用的初始化式。通常,这些初始化式会用于初始化新创建对象的数据成员。构造函数通常应确保其每个数据成员都完成了初始化。


The installation of wxWidgets is finished. On certain
platforms (e.g. Linux) you'll now have to run ldconfig
if you installed a shared library and also modify the
LD_LIBRARY_PATH (or equivalent) environment variable.

wxWidgets comes with no guarantees and doesn't claim
to be suitable for any purpose.

Read the wxWidgets Licence on licencing conditions.


阅读(559) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:双系统xp+CentOS从硬盘安装

给主人留下些什么吧!~~