C++????????????
???????????? ???????[ 2015/1/28 14:08:27 ] ????????C++ .NET ????
????????
?????????????C++ Primer Plus???????棬??????????飬???й??????????????????????????????????????????C++????????У?????????????????????????????????????????Щ???????shared_ptr?????????????????????????????????????????????????……??????????????C++??????????洦???????????????????????????????????????????????????????ü????
?????????????????????????????????????????????????????Щ?????
??????
????????????????????
????C++????????????
???????????auto_ptr??
????unique_ptr???????auto_ptr??
?????????????????
????????
????1. ????????????????
??????????????????????????
????void remodel(std::string & str)
????{
????std::string * ps = new std::string(str);
????...
????if (weird_thing())
????throw exception();
????str = *ps;
????delete ps;
????return;
????}
???????????????weird_thing()????true????delete????????У????????????й???
??????α????????????????????????????????throw exception();??????delete ps;????????????????????????????????????????????????delete??????????????к?????delete???????к?????????????????????????????????review????????????????????й?????????????????
????????????????remodel??????????????????????????????????????????????????????????????????????????????—??????ps??????潫?????????ps?????????????????????ж?e???
????????????????????????????????ps?????????????????????????????ps???????????????????檔??ps???????????????????????????????????????????????????????????????????????????????????????????????????????檔
?????????? auto_ptr??unique_ptr??shared_ptr?????????????????????????????????????????????????????????????????????壬??????????????????????????????????????дdelete??????????????????
????????????remodel()?????????????3????????У?
????????????memory??????????????????????
?????????string??????滻????string????????????
???????delete???
?????????????auto_ptr???ú?????????
????# include <memory>
????void remodel (std::string & str)
????{
????std::auto_ptr<std::string> ps (new std::string(str))??
????...
????if (weird_thing ())
????throw exception()??
????str = *ps??
????// delete ps?? NO LONGER NEEDED
????return;
????}
??????
???·???
??????????????????
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