讀書筆記 深入探索c 模型 1

2021-08-28 04:45:06 字數 1000 閱讀 7819

template

class point

point(type coord[dim])

}

type &operator(int i)

inline ostream &operator << (ostream &os, const point)

private:

type _coordt[dim];

};int main()

;pointobj_point(coord);

int ret = obj_point[10];

}1.inline和巨集的對比

2.類的引數化—模板類

template

3.為啥要過載操作符?

當時一直不明白寫好了的陣列,為啥要過載操作符,比如_coordt[dim],因為定義的變數是private的,為了向訪問平常寫的陣列一樣方便,所以過載

1.1 c++物件模式(the c++ object modle)

經過這邊書,原來c++物件模型原來還有2種,現在採用的是第3種

class point

;virtual ~point(){};

float x() const;

static int pointcount(); //對於member function:有static/non-static/virtual

private:

float _x;

static int _point_count; //對於member data:有static/non-static

};static int _point_count = 0;

float point::x() const

static int pointcount()

int main()

目前物件模型如下:

《深度探索C 物件模型》讀書筆記1

建構函式 1,在合成的預設建構函式中,只有成員物件,和基類子物件會被初始化,其他非靜態成員變數都不會被初始化。2,對於乙個class沒有乙個使用者定義的建構函式,那麼將會有預設的建構函式被隱式的宣告出來,有四種情況會造成編譯器會對乙個沒有沒有定義建構函式的類,自動合成乙個勾走函式 1,帶有預設建構函...

《深度探索C 物件模型》讀書筆記(5)

純虛函式 在設計抽象基類時,需要注意以下幾點 1 不要將destructor宣告為pure virtual function 如果將destructor宣告為pure virtual function,則設計者一定得定義它。因為每乙個derived class destructor會被編譯器加以擴充...

《深度探索C 物件模型》讀書筆記(6)

物件的構造和解構 一般而言,我們會把object盡可能放置在使用它的那個程式區段附近,這樣做可以節省不必要的物件產生操作和銷毀操作。全域性物件 全域性物件的靜態初始化策略包括以下幾個步驟 1 為每乙個需要靜態初始化的物件產生乙個 sti 函式,內含必要的constructor呼叫操作或inline ...