C++ 03 —— this

来源:互联网 发布:新蒙迪欧数据 编辑:程序博客网 时间:2024/06/08 15:52

源码

// 03This.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream.h"class Test{    int i;    int j;public:    void SetI(int ai)    {        cout << "this is :" << this << endl;        this->i = ai;// 这句话等价于 i = ai;    }};int main(int argc, char* argv[]){    Test t1, t2;    cout << "t1 addr is :" << &t1 << endl;    t1.SetI(1);    cout << "t2 addr is :" << &t2 << endl;    t2.SetI(1);    //结论:class的member function内部,默认有一个this指针,指向调用者对象    //问题:所有的member function都含有this指针吗?    return 0;}

问题:所有的member function都含有this指针吗?

静态成员函数没有this指针

原创粉丝点击