物件成員:
乙個物件中包含其他物件 如:
class line
當例項化這樣乙個物件時,會先例項化m_coora,再例項化m_coorb,最後例項化line
物件消亡時,會先銷毀line,再m_coorb,最後m_coora
如果座標類有乙個預設建構函式,那麼在例項化線段物件的時候,不使用初始化列表。
如果座標類要求必須有引數傳入,那麼在例項化線段類的時候,必須用初始化列表講相應的值傳遞給座標類
coordinate.h
class coornidate
;
coornidate.cpp
#include#include"coordinate.h"
using namespace std;
coornidate::coornidate(int x,int y)
;
line.cpp
#include#include"line.h"
using namespace std;
line::line(int x1,int y1,int x2,int y2):m_coora(x1,y1),m_coorb(x2,y2)
coornidate() (1,2)
coornidate() (3,4)
line()
(1,2)
(3,4)
~line()
~coornidate() (3,4)
~coornidate() (1,2)
C 物件成員
上圖 表示一條線的類需要兩個點的物件 實際上線段的例項化應該有引數 y 可以用初始化列表也可以不用 coordiante coordiante void coordiante setx int x int coordiante getx void coordiante sety int y int ...
c 之物件成員
class line 線段類物件呼叫了下面的點類的物件來構成他 coordinate coordinate int x,int y void line setb int x,int y void line printinfo cout p printinfo delete p p null retu...
c 類成員物件
成員物件 當乙個類的成員是另乙個類的物件時,這個物件就叫成員物件。1 出現成員物件時,如果成員物件的建構函式是有參建構函式,則該類的初始化列表需要對成員物件進行初始化。class member class test 2 乙個有成員物件的類例項化時要先呼叫成員物件的建構函式,然後再呼叫該類的建構函式,...