{"id":376883,"date":"2024-05-23T15:00:34","date_gmt":"2024-05-23T15:00:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=376883"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=376883","title":{"rendered":"<span>\u0421++: \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/pn\/ki\/qb\/pnkiqbylvrwvi_ui1gaj806pap0.png\" alt=\"\u041f\u0440\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438\" data-src=\"https:\/\/habrastorage.org\/webt\/pn\/ki\/qb\/pnkiqbylvrwvi_ui1gaj806pap0.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0443\u0448\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u041e\u041e\u041f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C++, \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u042d\u0442\u0438\u043c \u043c\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043c \u0446\u0438\u043a\u043b \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439, \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d\u043d\u044b\u0439 \u043e\u0431\u0437\u043e\u0440\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0438\u0433\u0440\u043e\u0432\u043e\u043c \u0434\u0432\u0438\u0436\u043a\u0435 qdEngine.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"neudachnaya-realizaciya-ochistki-resursov-v-kode-qdengine\">\u041d\u0435\u0443\u0434\u0430\u0447\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0432 \u043a\u043e\u0434\u0435 qdEngine<\/h2>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u043a\u0430 qdEngine:<\/p>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/pvs-studio\/articles\/810987\/\">\u0422\u043e\u043f 10 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439 PVS-Studio<\/a>.<\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/pvs-studio\/articles\/812795\/\">\u0423\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0435 C++ \u043a\u043e\u0434\u0430<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/pvs-studio\/articles\/814821\/\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0434\u0435\u0441\u044f\u0442\u043a\u0430 \u0431\u0430\u0433\u043e\u0432<\/a><\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u0438\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439 \u0443 \u043c\u0435\u043d\u044f \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 PVS-Studio, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0441\u0432\u044f\u0442\u0438\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0437\u0430\u043c\u0435\u0442\u043a\u0443. \u0412\u043e\u0442 \u043e\u043d\u043e:<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v1053\/\">V1053<\/a> [<a href=\"https:\/\/wiki.sei.cmu.edu\/confluence\/display\/cplusplus\/OOP50-CPP.+Do+not+invoke+virtual+functions+from+constructors+or+destructors\">CERT-OOP50-CPP<\/a>] Calling the &#8216;Finit&#8217; virtual function in the destructor may lead to unexpected result at runtime. gr_dispatcher.cpp 54<\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 C++ \u0447\u0451\u0442\u043a\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043f\u0440\u044f\u043c\u043e-\u0442\u0430\u043a\u0438 \u043f\u0440\u0438\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u043e\u0433\u0438\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u044b \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e\u0442 \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u0412 \u0441\u0432\u043e\u0451 \u0432\u0440\u0435\u043c\u044f \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u0441\u0442\u0430\u0442\u044c\u044e &#171;<a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/0891\/\">\u0412\u044b\u0437\u043e\u0432 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u0445 \u0438 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u0445 (C++)<\/a>&#171;. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u043e\u0432\u0438\u0447\u043e\u043a \u0432 C++ \u0438\u043b\u0438 \u043f\u043e\u0434\u0437\u0430\u0431\u044b\u043b\u0438, \u043a\u0430\u043a \u0432\u0441\u0451 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u043e \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u0447\u0442\u0435\u043d\u0438\u044f \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u043d\u0435\u0451. \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0435\u0451 \u0442\u0435\u043c, \u043a\u0442\u043e \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442, \u043e \u043a\u0430\u043a\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0438\u0434\u0451\u0442 \u0440\u0435\u0447\u044c.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0434, \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0439\u0441\u044f \u043a \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044e, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u043d\u043e \u0432\u044b \u0441\u043c\u0435\u043b\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0435\u0433\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c. \u041d\u0438\u0436\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0432\u0441\u0451 \u043d\u0430 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041a\u043e\u0434 \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 qdEngine.<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<p>\u0412 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>Finit<\/em>. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u043b\u0430\u0441\u0441-\u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a <em>DDraw_grDispatcher<\/em> \u0443\u0436\u0435 \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d, \u0442\u043e \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>Finit<\/em> \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">class grDispatcher {   ....   virtual ~grDispatcher();   virtual bool Finit();   .... };  grDispatcher::~grDispatcher() {   Finit();   if (dispatcher_ptr_ == this) dispatcher_ptr_ = 0; }  bool grDispatcher::Finit() { #ifdef _GR_ENABLE_ZBUFFER   free_zbuffer(); #endif    flags &amp;= ~GR_INITED;   SizeX = SizeY = 0;   wndPosX = wndPosY = 0;   screenBuf = NULL;   delete  yTable;   yTable = NULL;    return true; }  class DDraw_grDispatcher : public grDispatcher {   ....   ~DDraw_grDispatcher();   bool Finit();   .... };  DDraw_grDispatcher::~DDraw_grDispatcher() {   if (ddobj_)   {     ddobj_ -> Release();     ddobj_ = NULL;   }    video_modes_.clear(); }  bool DDraw_grDispatcher::Finit() {   grDispatcher::Finit();    if (back_surface_)   {     while(       back_surface_ -> GetBltStatus(DDGBS_ISBLTDONE) == DDERR_WASSTILLDRAWING);     back_surface_ -> Unlock(&amp;back_surface_obj_);     ddobj_ -> SetCooperativeLevel((HWND)Get_hWnd(),DDSCL_NORMAL);     if (fullscreen_ &amp;&amp; ddobj_) ddobj_ -> RestoreDisplayMode();   }    if (prim_surface_)   {     prim_surface_ -> Release();     prim_surface_ = NULL;   }    if (back_surface_)   {     back_surface_ -> Release();     back_surface_ = NULL;   }    return true; }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h2 id=\"razbor-oshibki-na-sinteticheskom-kode\">\u0420\u0430\u0437\u0431\u043e\u0440 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043a\u043e\u0434\u0435<\/h2>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f, \u0432 \u0447\u0451\u043c \u0441\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u0434 \u0438 \u0441\u0430\u0439\u0442 <a href=\"https:\/\/godbolt.org\/\">Compiler Explorer<\/a>, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0441\u0442\u0440\u043e \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<p>  <\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0443\u044e \u043d\u0435\u043a\u0438\u043c\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include &lt;memory> #include &lt;iostream>  class Resource { public:   void Create() {}   void Destroy() {} };  class A {   std::unique_ptr&lt;Resource> m_a;  public:   void InitA()   {     m_a = std::make_unique&lt;Resource>();     m_a->Create();   }    virtual ~A()   {     std::cout &lt;&lt; \"~A()\" &lt;&lt; std::endl;     if (m_a != nullptr)       m_a->Destroy();   } };  int main() {   std::unique_ptr&lt;A> p = std::make_unique&lt;A>();   return 0; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043a\u0430 \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u044b\u0439 <a href=\"https:\/\/godbolt.org\/z\/z8EdqWv3n\">online \u043f\u0440\u0438\u043c\u0435\u0440<\/a> \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u044b\u0432\u0430\u0435\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">~A()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u043d\u0435 \u0434\u043e\u0436\u0438\u0434\u0430\u044f\u0441\u044c \u0432\u044b\u0437\u043e\u0432\u0430 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430. \u0412 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0430. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include &lt;memory> #include &lt;iostream>  class Resource { public:   void Create() {}   void Destroy() {} };  class A {   std::unique_ptr&lt;Resource> m_a;  public:   void InitA()   {     m_a = std::make_unique&lt;Resource>();     m_a->Create();   }    virtual void Reset()   {     std::cout &lt;&lt; \"A::Reset()\" &lt;&lt; std::endl;     if (m_a != nullptr)     {       m_a->Destroy();       m_a.reset();     }   }    virtual ~A()   {     std::cout &lt;&lt; \"~A()\" &lt;&lt; std::endl;     Reset();   } };  int main() {   std::unique_ptr&lt;A> p = std::make_unique&lt;A>();   return 0; }<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/godbolt.org\/z\/hTs4YGGqc\">Online \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">~A() A::Reset()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>Reset<\/em>, \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u044e\u0449\u0430\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434, \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0441\u0430\u043c \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043a\u0430 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0451 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441-\u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include &lt;memory> #include &lt;iostream>  class Resource { public:   void Create() {}   void Destroy() {} };  class A {   std::unique_ptr&lt;Resource> m_a;  public:   void InitA()   {     m_a = std::make_unique&lt;Resource>();     m_a->Create();   }    virtual void Reset()   {     std::cout &lt;&lt; \"A::Reset()\" &lt;&lt; std::endl;     if (m_a != nullptr)     {       m_a->Destroy();       m_a.reset();     }   }    virtual ~A()   {     std::cout &lt;&lt; \"~A()\" &lt;&lt; std::endl;     Reset();   } };  class B : public A {   std::unique_ptr&lt;Resource> m_b;  public:   void InitB()   {     m_b = std::make_unique&lt;Resource>();     m_b->Create();   }    void Reset()   {     std::cout &lt;&lt; \"B::Reset()\" &lt;&lt; std::endl;     if (m_b != nullptr)     {       m_b->Destroy();       m_b.reset();     }     A::Reset();   }    ~B()   {     std::cout &lt;&lt; \"~B()\" &lt;&lt; std::endl;     Reset();   } };  int main() {   std::unique_ptr&lt;A> p = std::make_unique&lt;B>();   p->Reset();   std::cout &lt;&lt; \"------------\" &lt;&lt; std::endl;   p->InitA();   return 0; }<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/godbolt.org\/z\/rPzbdrfo1\">Online \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">B::Reset() A::Reset() ------------ ~B() B::Reset() A::Reset() ~A() A::Reset()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u044f\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>Reset<\/em>, \u0442\u043e \u0432\u0441\u0451 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u043e. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <em>B::Reset()<\/em>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0434\u043d\u043e\u0438\u043c\u0451\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u0437 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c. \u041a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>Reset<\/em>. \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>Reset<\/em> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0437 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435, \u0442\u043e \u0432\u0441\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u0443\u0434\u0435\u043c \u0443\u0441\u0443\u0433\u0443\u0431\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443. \u0412\u0441\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043b\u0438\u0448\u043d\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/godbolt.org\/z\/dnGKEr95r\">\u0412\u044b\u0432\u043e\u0434 \u043a\u043e\u0434\u0430<\/a>, \u0433\u0434\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">C::Reset() B::Reset() A::Reset() ------------ ~C() C::Reset() B::Reset() A::Reset() ~B() B::Reset() A::Reset() ~A() A::Reset()<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430. \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u044d\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u043e\u043d\u0430 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430 \u043d\u0430\u043c. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0442\u0430\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0435\u0431\u0435 \u043c\u043e\u0433\u0443\u0442 \u0436\u0438\u0442\u044c, \u043e\u0441\u0442\u0430\u0432\u0430\u044f\u0441\u044c \u043d\u0435\u0437\u0430\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c\u0438: \u043a\u043e\u0434 \u0432\u0435\u0434\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0431\u0440\u043e\u0441\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445 \u0438 \u043d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438. <\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u0438 \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u0435\u0451 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0440\u0438\u0441\u043a\u0443\u0435\u0442 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0434\u0432\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0442\u0438\u043f\u043e\u0432\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442.<\/strong> \u041e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>Reset<\/em> \u043d\u0435\u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0432 \u043d\u0438\u0445 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b (<em>x::Reset<\/em>). \u0422\u043e\u0433\u0434\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>Reset<\/em> \u0438\u0437 \u0441\u0432\u043e\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u042d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0431\u0435\u0440\u0451\u0442 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <em>Reset<\/em> \u0438\u0437\u0432\u043d\u0435. <a href=\"https:\/\/godbolt.org\/z\/TM9eqo4Pz\">\u0421\u043b\u043e\u043c\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">A::Reset()   \/\/ \u0421\u043b\u043e\u043c\u0430\u043b\u0438 \u043e\u0447\u0438\u0441\u0442\u043a\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438\u0437 \u0432\u043d\u0435 ------------ ~C() C::Reset() ~B() B::Reset() ~A() A::Reset()<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442.<\/strong> \u0412\u044b\u0437\u0432\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>Reset<\/em> \u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0438\u0437 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u042d\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c C++ \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>Reset<\/em>, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435, \u0430 \u043d\u0435 \u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430\u0445. \u042d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043a \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u0432\u044b\u0437\u043e\u0432\u0430 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 <em>~A()<\/em> \u0432\u0441\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0438 \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d\u044b, \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 \u043d\u0438\u0445 \u043d\u0435\u043b\u044c\u0437\u044f. <a href=\"https:\/\/godbolt.org\/z\/6cs9aj4aG\">\u0421\u043b\u043e\u043c\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">C::Reset() B::Reset() A::Reset() ------------ ~C() ~B() ~A() A::Reset()  \/\/ \u041e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0442\u0438\u043f \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0431\u044b\u043b \u043d\u0430\u0439\u0434\u0435\u043d \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 qdEngine \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f PVS-Studio. \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043d\u0430\u0447\u0430\u043b\u0443 \u0441\u0442\u0430\u0442\u044c\u0438 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0438\u0437 \u0434\u0432\u0438\u0436\u043a\u0430.<\/p>\n<p>  <\/p>\n<h2 id=\"ispravlennyy-sinteticheskiy-kod\">\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u0434<\/h2>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0436\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432?<\/p>\n<p>  <\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0447\u0438\u0441\u0442\u043a\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0432 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0434\u043b\u044f \u0438\u0445 \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0438\u0437\u0432\u043d\u0435. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430 \u043e\u0447\u0438\u0441\u0442\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u043b\u0430\u0441\u0441\u0430\u0445, \u0433\u0434\u0435 \u043e\u043d\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b. \u041d\u0430\u0437\u043e\u0432\u0451\u043c \u0438\u0445 <em>ResetImpl<\/em> \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0438 \u043d\u0435 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0434\u043b\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0414\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c <em>ResetImpl<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <em>Reset<\/em> \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439. \u041e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0438\u0449\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u0441\u0435\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0441\u0451 \u0442\u0435 \u0436\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>ResetImpl<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0435\u0440\u0451\u043c \u0432\u0441\u0451 \u0432\u043c\u0435\u0441\u0442\u0435 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include &lt;memory> #include &lt;iostream>  class Resource { public:   void Create() {}   void Destroy() {} };  class A {   std::unique_ptr&lt;Resource> m_a;    void ResetImpl()   {     std::cout &lt;&lt; \"A::ResetImpl()\" &lt;&lt; std::endl;     if (m_a != nullptr)     {       m_a->Destroy();       m_a.reset();     }   }  public:   void InitA()   {     m_a = std::make_unique&lt;Resource>();     m_a->Create();   }    virtual void Reset()   {     std::cout &lt;&lt; \"A::Reset()\" &lt;&lt; std::endl;     ResetImpl();   }    virtual ~A()   {     std::cout &lt;&lt; \"~A()\" &lt;&lt; std::endl;     ResetImpl();   } };  class B : public A {   std::unique_ptr&lt;Resource> m_b;    void ResetImpl()   {     std::cout &lt;&lt; \"B::ResetImpl()\" &lt;&lt; std::endl;     if (m_b != nullptr)     {       m_b->Destroy();       m_b.reset();     }   }  public:   void InitB()   {     m_b = std::make_unique&lt;Resource>();     m_b->Create();   }    virtual void Reset()   {     std::cout &lt;&lt; \"B::Reset()\" &lt;&lt; std::endl;     ResetImpl();     A::Reset();   }    virtual ~B()   {     std::cout &lt;&lt; \"~B()\" &lt;&lt; std::endl;     ResetImpl();   } };  class C : public B {   std::unique_ptr&lt;Resource> m_c;    void ResetImpl()   {     std::cout &lt;&lt; \"C::ResetImpl()\" &lt;&lt; std::endl;     if (m_c != nullptr)     {       m_c->Destroy();       m_c.reset();     }   }  public:   void InitC()   {     m_c = std::make_unique&lt;Resource>();     m_c->Create();   }    virtual void Reset()   {     std::cout &lt;&lt; \"C::Reset()\" &lt;&lt; std::endl;     ResetImpl();     B::Reset();   }    virtual ~C()   {     std::cout &lt;&lt; \"~C()\" &lt;&lt; std::endl;     ResetImpl();   } };  int main() {   std::unique_ptr&lt;A> p = std::make_unique&lt;C>();   p->Reset();   std::cout &lt;&lt; \"------------\" &lt;&lt; std::endl;   return 0; }<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/godbolt.org\/z\/G3ohvE6EY\">Online \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">C::Reset() C::ResetImpl() B::Reset() B::ResetImpl() A::Reset() A::ResetImpl() ------------ ~C() C::ResetImpl() ~B() B::ResetImpl() ~A() A::ResetImpl()<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0435 \u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0440\u0430\u0441\u0438\u0432\u043e. \u0412 \u043d\u0451\u043c \u0440\u044f\u0431\u0438\u0442 \u043e\u0442 \u0431\u0443\u043a\u0432 A, B, C, \u0438 \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u043e\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c\u0441\u044f. \u041f\u0440\u043e\u0441\u0442\u0438\u043c \u044d\u0442\u043e \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c. \u0413\u043b\u0430\u0432\u043d\u043e\u0435, \u0447\u0442\u043e \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0438 \u043c\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u043e\u0442 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<p>  <\/p>\n<h2 id=\"primechanie\">\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0421\u0445\u043e\u0436\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0441 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u043c\u0438, \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437. \u041f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0438 \u0435\u0451 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u0432\u0438\u0434\u0435\u043e \u043f\u0440\u043e code-review \u043f\u0440\u043e\u0435\u043a\u0442\u0430 Lyra (\u0440\u0430\u0437\u0434\u0435\u043b &#171;\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 Replit&#187;). \u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 <a href=\"https:\/\/www.youtube.com\/watch?v=ZDR8sP9ei2k&amp;t=2101s\">0:35:01<\/a>.<\/p>\n<p>  <\/p>\n<div class=\"oembed\">\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/664f2b6e315cc3d4a119e9b4\" data-style=\"\" id=\"664f2b6e315cc3d4a119e9b4\" width=\"\"><\/div>\n<\/div>\n<p>  <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u0432\u044b\u0437\u043e\u0432 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c \u043f\u043b\u043e\u0445\u043e\u0433\u043e \u0434\u0438\u0437\u0430\u0439\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u041a\u0430\u043a \u0440\u0430\u0437 \u044d\u0442\u043e \u043c\u044b \u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u043b\u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <em>qdEngine<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 PVS-Studio \u0432\u044b\u0434\u0430\u0451\u0442 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 <a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v1053\/\">V1053<\/a> \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0438\u043b\u0438 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u042d\u0442\u043e \u043f\u043e\u0432\u043e\u0434 \u0435\u0449\u0451 \u0440\u0430\u0437 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434, \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0438\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u0441 \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u0439 \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u0435\u0439, \u0442\u043e \u043f\u0440\u043e\u0448\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434: Andrey Karpov. <a href=\"https:\/\/pvs-studio.com\/en\/blog\/posts\/cpp\/1125\/\">C++: freeing resources in destructors using helper functions<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/816619\/\"> https:\/\/habr.com\/ru\/articles\/816619\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/pn\/ki\/qb\/pnkiqbylvrwvi_ui1gaj806pap0.png\" alt=\"\u041f\u0440\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438\" data-src=\"https:\/\/habrastorage.org\/webt\/pn\/ki\/qb\/pnkiqbylvrwvi_ui1gaj806pap0.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0443\u0448\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u041e\u041e\u041f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C++, \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u042d\u0442\u0438\u043c \u043c\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043c \u0446\u0438\u043a\u043b \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439, \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d\u043d\u044b\u0439 \u043e\u0431\u0437\u043e\u0440\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0438\u0433\u0440\u043e\u0432\u043e\u043c \u0434\u0432\u0438\u0436\u043a\u0435 qdEngine.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-376883","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/376883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=376883"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/376883\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=376883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=376883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=376883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}