\u7f16\u7a0b<\/a>\u5f00\u53d1\u201d<\/p> \n \r\ntemplate\n \n \r\nclass auto_ptr {\r\npublic:\r\n explicit auto_ptr(T* p = 0);\r\n template\n \n auto_ptr(auto_ptr& rhs); ~auto_ptr(); template\n \n auto_ptr\n \n & operator=(auto_ptr& rhs); T& operator*() const; T* operator->() const; T* get() const; T* release(); void reset(T *p = 0); private: T *pointee; }; template\n \n inline auto_ptr\n \n ::auto_ptr(T *p = 0) : pointee(p) {} template\n \n template\n \n inline auto_ptr\n \n ::auto_ptr(auto_ptr& rhs) : pointee(rhs.release()) {} template\n \n inline auto_ptr\n \n ::~auto_ptr() { delete pointee; } template\n \n template\n \n inline auto_ptr\n \n & auto_ptr\n \n ::operator=(auto_ptr& rhs) { if (this != &rhs) reset(rhs.release()); \/\/if (rhs.get() != this->get()) reset(rhs.release()); return *this; } template\n \n inline T& auto_ptr\n \n ::operator*() const { return *pointee; } template\n \n inline T* auto_ptr\n \n ::operator->() const { return pointee; } template\n \n inline T* auto_ptr\n \n ::get() const { return pointee; } template\n \n inline T* auto_ptr\n \n ::release() { T* oldPointee = pointee; pointee = 0; return oldPointee; } template\n \n inline void auto_ptr\n \n ::reset(T* p) { if (pointee != p) { delete pointee; pointee = p; } }\n <\/t>\n <\/class>\n <\/t>\n <\/class>\n <\/t>\n <\/class>\n <\/t>\n <\/class>\n <\/t>\n <\/class>\n <\/t>\n <\/t>\n <\/class>\n <\/class>\n <\/t>\n <\/class>\n <\/t>\n <\/class>\n <\/class>\n <\/t>\n <\/class>\n <\/t>\n <\/class>\n <\/class>\n <\/class><\/pre> \n \u5f02\u5e38
C2243 \u2018type cast\u2019: conversion from \u2018Drived \u2019 to \u2018Base <\/em>\u2019 exists, but is inaccessible
\u3002\u3002\u3002\u3002
E0269 conversion to inaccessible base class \u201cBase\u201d is not allowed<\/p> \n \r\nclass Base{\r\npublic:\r\n void basemem() { };\r\n int get() { \r\n return i;\r\n }\r\nprotected:\r\n int i;\r\n};\r\nclass Drived : private Base{ \/\/ \u95ee\u9898\u51fa\u5728private \u9ed8\u8ba4\u4e5f\u662fprivate \u6539\u4e3apublic\u5c31\u662f\r\n int use_base() { return i; }\r\n};\r\nint main() {\r\n\r\n auto_ptr<\/pre> \n a(new Base); auto_ptr\n \n d(new Drived); Drived* p = d.release(); p->basemem(); \/\/ \u4e0d\u53ef\u8bbf\u95ee Base* p1 = a.release(); p1->basemem(); \/\/ \u53ef\u8bbf\u95ee p1 = p; \/\/ \u8be5\u4e0d\u8be5\u8bbf\u95ee\uff1f \u6240\u4ee5\u8fd9\u6837\u505a\u7f16\u8bd1\u5668\u4e0d\u5141\u8bb8 \u6539\u6210public inheritance \u5c31\u597d\u4e86 auto_ptr \n b(p1); }\n <\/drived> \n<\/div>","orderid":"0","title":"More Effective c++ 28. Smart Pointer\u201c\u7f16\u7a0b\u5f00\u53d1\u201d","smalltitle":"","mid":"0","fname":"c++\u7f16\u7a0b\u57fa\u7840","special_id":"0","bak_id":"0","info":"0","hits":"242","pages":"1","comments":"0","posttime":"2017-12-14 14:31:36","list":"1513233096","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"More<\/A> Effective<\/A> 28.<\/A> Smart<\/A> Pointer<\/A> \u7f16\u7a0b<\/A> \u5f00\u53d1<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"113.110.149.170","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"More Effective c++ 28. Smart Pointer\u201c\u7f16\u7a0b\u5f00\u53d1\u201d","lastview":"1711662809","digg_num":"3","digg_time":"1711458373","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}