20.10.19,學習c++的第九天
乙個空物件占用乙個位元組的空間。
只有非靜態成員變數才屬於類的物件上。
this指標指向被呼叫的成員函式所屬的物件
this指標的用途:
在成員行為中使用成員屬性,預設是「this->menber」。
//空指標訪問成員函式
class
person
void
showperson()
cout << mage << endl;
// 預設為 cout << this->mage << endl;
}public
:int mage;};
void
test01()
c++中空指標也是可以呼叫成員函式的,但是也要注意有沒有用到this指標。如果用到this指標,需要加以判斷保證**的健壯性(如上所示)。 c 入門程式設計學習記錄4
20.8.5,學習c 的第四天 結構體的知識以及用法 include include using namespace std struct student struct teacher int main 結構體陣列 struct student stuarr 2 結構體指標 struct stude...
c 入門程式設計學習記錄6
20.10.6,學習c 的第六天 函式預設引數 int func int a,int b 10,int c 10 1.如果某個位置引數有預設值,那麼從這個位置往後,從左向右,必須都要有預設值 2.如果函式宣告有預設值,函式實現的時候就不能有預設引數 宣告和實現只能有乙個預設引數 函式佔位引數 voi...
c 入門程式設計學習記錄8
20.10.12,學習c 的第八天 建構函式和析構函式 class person 析構函式 person 建構函式的分類與呼叫 class person 有參建構函式 person int a 拷貝建構函式 person const person p 析構函式 person public int a...