C++?????????黯?????????????
???????????? ???????[ 2012/9/17 9:46:04 ] ????????
???????????????????????????????????????????????????麯??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????
????1??????????effective c++ ????????????У?????????????????е??????????????????????????????????黯??????????????????
class base { //????????????????????????麯???????乹???????? public: .... }; class derive1??public base { public: .... }; class derive1??public base { //???????κδ??麯?? public: .... }; class derive2??public base { //???????κδ??麯?? public: .... }; class object { public: ... private: list }; |
???????????????У?class object???????list???????????base?????????????base?????????????????list?е?????????derive1?????derive2???????????????????
??????object????????????????????????
object:object(base* b) { |
????2??????????????????“?麯???????????”?????е?????????????c++????????????????????????derived class?????????base class??????麯??????????????????????????????????????????????????????????????????????????????base class?????derived class???????????????????????????base class??derived class?????????c++??????????????????????virtual copy constructors???????????
class base { public: //????virtual copy constructor virtual base *clone() const=0; .... }; class derive1??public base { //????virtual copy constructor virtual derive1 *clone() const { return new derive1(*this); } .... }; class derive2??public base { //????virtual copy constructor virtual derive2 *clone() const { return new derive2(*this); } .... }; class object { public: object(const base& rhs); ... private: list }; |
????object??????????У?
object:object(const base& rhs) { for(list components.push_back((*it)->clone());//???????base???????????components listβ?? } } |
??????????????????????????????????????????????麯?????????????????????????????????黯??Ч????
??????
???·???
??????????????????
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