this指针
来源:互联网 发布:win10公司网络视频屏蔽 编辑:程序博客网 时间:2024/06/17 02:22
1.个简单的例子:
class AA
{
int a;
int b;
void show(){cout < <a;cout < <b}
}
AA a;
a.show();
我的看法是 对象a在调用类的成员函数show()的时候 会把自己的“特权地址”作为参数“隐式”的传送给成员函数show()的隐藏形参this, 这样成员函数show()就能通过this指针来访问该对象的数据成员 a,b了
所以 void show(){cout < <a;cout < <b} 的真实形态应该是:
void show(AA*this){cout < <this-> a;cout < <this-> b}
2this在成员函数的开始前构造,在成员的结束后清除。
这个生命周期同任何一个函数的参数是一样的,没有任何区别。
因为,成员函数默认第一个参数就是this。
举例:
class A{
public:
int func(int p){}
};
func的原型在编译器看来,应该是
int func(A* const this, int p);
- this指针
- this指针
- this指针
- this指针
- this指针
- this 指针
- this指针
- this指针----
- this指针
- this 指针
- This 指针
- this指针
- This指针
- this指针
- this指针
- this 指针
- this指针
- this指针
- A标签触发onclick事件而不跳转
- 基于dic.cn webapi的linux终端词典工具
- 用软引用阻止内存泄漏
- 内存布局-大小端模式
- QQ登录PHP OAuth示例
- this指针
- /etc/fstab文件详解
- Gallery 中放置button 点击事件处理
- 试试Live Witer
- 在SSIS中使用SharePoint列表作为源和目标
- 在SSIS中使用SharePoint列表作为源和目标
- GB13000-2010汉字字符集及其在Unicode 6.0中的码位变化
- GNU C 与ANSI C 相比,独特的9个地方(转载
- myeclipse8.5中写struts.xml配置文件时,没有提示功能.txt