C++11????????????????
???????????? ???????[ 2016/1/19 10:40:43 ] ??????????????????? .NET
??????????
??????????????????????????????????????????????????????????switch-case????????key????????????????????????????α????
Message* create(int type)
{
switch (type)
{
case MSG_PGSTATS:
m = new MPGStats;
break;
case MSG_PGSTATSACK:
m = new MPGStatsAck;
break;
case CEPH_MSG_STATFS:
m = new MStatfs;
break;
case CEPH_MSG_STATFS_REPLY:
m = new MStatfsReply;
break;
case MSG_GETPOOLSTATS:
m = new MGetPoolStats;
break;
default:
break;
}
}
?????????????????????????????????switch-case????????????????????????п??????????case???????????????????????????????????????????????????????Ρ????????Щ??????switch-case?????????????????????????????????????????????????????????
????????????????????????-????????????????????????д?????????????????????????????switch-case???
??????????
??????????????????????·???£?
?????????????????????
?????????????????洴???????key???????????
?????????????????????????????????????????????
??????????????????????????
????????????????е?????????????????
???????У????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Щ?????????????????????????????????????塣
???????????????????C++11??????????????????????
??????????????????????
????struct factory
????{
????static factory& get()
????{
????static factory instance;
????return instance;
????}
????private:
????factory() {};
????factory(const factory&) = delete;
????factory(factory&&) = delete;
????static std::map<std::string?? std::function<Message*()>> map_;
????};
??????C++11?е???????????????????????????????????????ü??????????????????????????????C++11?о?????????????????????????????????????map??map???????????function???????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11