Re: [問題] template一問

看板C_and_CPP作者 (做遊戲的心)時間14年前 (2011/06/18 11:37), 編輯推噓1(103)
留言4則, 3人參與, 最新討論串4/9 (看更多)
※ 引述《legnaleurc (CA)》之銘言: : class Factory { : public: : typedef std::function< Base *() > Creator; : static Base * Create( int id ); : static bool Register( int id, Creator c ); : private: : static std::map< int, Creator > f_; : }; : Base * Factory::Create( int id ) { : std::map< int, Creator >::const_iterator it = f_.find( id ); : if( it == f_.end() ) { : return NULL; : } : return it->second(); : } : bool Register( int id, Creator c ) { : if( f_.find( id ) != f_.end() ) { : return false; : } : f_.insert( std::make_pair( id, c ) ); : return true; : } : // register : Factory::Register( 1, []() { : return new D1; : } ); 感謝L大的幫忙 但原諒小弟基礎不好 想請問一下 為什麼Factory::Register中的第二個參數可以這樣寫呢? Factory::Register( 1, []() { return new D1; } ) ^^尤其是這裡 看不懂 以下恕刪~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.160.159.34

06/18 19:39, , 1F
lambda?
06/18 19:39, 1F

06/18 19:55, , 2F
這樣好像有點問題...
06/18 19:55, 2F

06/18 22:26, , 3F
~"~我其實也想問那樣寫怪怪的,而且依開始回傳值不是bool
06/18 22:26, 3F

06/18 22:26, , 4F
?
06/18 22:26, 4F
文章代碼(AID): #1D_8tezP (C_and_CPP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
問題
1
2
以下文章回應了本文
問題
3
16
完整討論串 (本文為第 4 之 9 篇):
問題
2
3
問題
5
34
問題
3
16
問題
3
7
問題
1
4
問題
1
2
問題
1
5
問題
0
18
文章代碼(AID): #1D_8tezP (C_and_CPP)