源碼
// 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指針