Re: [問題] template一問
※ 引述《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
06/18 19:39, 1F
推
06/18 19:55, , 2F
06/18 19:55, 2F
→
06/18 22:26, , 3F
06/18 22:26, 3F
→
06/18 22:26, , 4F
06/18 22:26, 4F
討論串 (同標題文章)