[問題] strategy pattern的問題

看板C_and_CPP作者 (不下棋)時間14年前 (2011/03/27 12:21), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串1/1
http://www.cnblogs.com/oomusou/archive/2007/03/26/687727.html 上面網頁中 ISO C++ by Interface裡的 class Grapher { public: Grapher(IDrawStrategy* drawStrategy = 0) : _drawStrategy(drawStrategy) {} public: void drawShape() const; void setShape(IDrawStrategy* drawStrategy); protected: IDrawStrategy* _drawStrategy; }; 想請問下面這段是什麼意思呢? public: Grapher(IDrawStrategy* drawStrategy = 0) : _drawStrategy(drawStrategy) {} -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.125.135.200

03/27 12:40, , 1F
一個 Grapher 的建構子, 收一個 IDrawStrategy * 型態的參數
03/27 12:40, 1F

03/27 12:41, , 2F
預設值為 0 (對指標即為 NULL), 然後用這個參數去初始化
03/27 12:41, 2F

03/27 12:41, , 3F
_drawStrategy 這個 member variable
03/27 12:41, 3F

03/27 12:41, , 4F
詳細說明請 google://initialization list
03/27 12:41, 4F
文章代碼(AID): #1DZhj4sx (C_and_CPP)