{"id":252929,"date":"2015-03-12T15:08:02","date_gmt":"2015-03-12T11:08:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=252929"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=252929","title":{"rendered":"\u041e\u043f\u0430\u0441\u043d\u044b\u0439 copy elision"},"content":{"rendered":"<p> \t\t\t<img decoding=\"async\" src=\"http:\/\/hsto.org\/files\/ebb\/f65\/6bd\/ebbf656bda4946a9b2dd9449f4b31dc1.png\"\/><\/p>\n<p>  \u0423\u0436\u0435 \u0433\u043e\u0434 \u0432 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0435 \u043e\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0440\u0435\u043c\u044f \u044f \u043f\u0438\u043b\u044e \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u0441\u043c\u0435\u0441\u0438 Maven \u0438 Spring \u0434\u043b\u044f \u0421++. \u0412\u0430\u0436\u043d\u043e\u0439 \u0435\u0451 \u0447\u0430\u0441\u0442\u044c\u044e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A3%D0%BC%D0%BD%D1%8B%D0%B9_%D1%83%D0%BA%D0%B0%D0%B7%D0%B0%D1%82%D0%B5%D0%BB%D1%8C\">\u0443\u043c\u043d\u044b\u0445 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439<\/a>. \u0417\u0430\u0447\u0435\u043c \u043c\u043d\u0435 \u0432\u0441\u0451 \u044d\u0442\u043e \u2014 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0435\u043c\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u0434\u043d\u0430, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0444\u0438\u0447\u0430 \u0421++ \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043b\u0430 \u043c\u0435\u043d\u044f \u0443\u0441\u043e\u043c\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0437\u0434\u0440\u0430\u0432\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>1. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/h3>\n<p>  \u0423\u043c\u043d\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0431\u044b\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u043d\u044b \u0435\u0449\u0451 \u043b\u0435\u0442\u043e\u043c \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u0433\u043e\u0434\u0430.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0437\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">template&lt;typename T_Type, typename T_Holding, typename T_Access&gt; class DReference {  . . . \tIDSharedMemoryHolder *_holder;  \tvoid retain(IDSharedMemoryHolder *inHolder) { . . . } \tvoid release() { . . . }   . . .  \t~DReference() { release(); }  \ttemplate&lt;typename T_OtherType, \t\t\ttypename T_OtherHolding, \t\t\ttypename T_OtherAccess&gt; \tDReference( \t\t\tconst DReference&lt;T_OtherType, T_OtherHolding, T_OtherAccess&gt; & \t\t\t\t\tinLReference) : _holder(NULL), _holding(), _access() \t{ \t\tretain(inLReference._holder); \t}  . . .   } <\/code><\/pre>\n<p>  \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b-\u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443. \u041c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0438\u0445 \u0442\u0438\u043f\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u0443\u043c\u043d\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f. <i>IDSharedMemoryHolder<\/i> \u2014 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0430\u043c\u044f\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0427\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <i>retain()<\/i> \u0443\u043c\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0432\u043b\u0430\u0434\u0435\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c (\u0434\u043b\u044f strong reference-\u0430 <i>++ref_count<\/i>). \u041f\u043e \u0432\u044b\u0437\u043e\u0432\u0443 <i>release()<\/i> \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 (\u0434\u043b\u044f strong reference-\u0430 <i>&#8212;ref_count<\/i> \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0435\u0441\u043b\u0438 <i>ref_count == 0<\/i>).<\/p>\n<p>  <i>\u042f \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u043e\u043f\u0443\u0441\u0442\u0438\u043b \u0437\u0434\u0435\u0441\u044c \u0432\u0435\u0449\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438 \u0441 retain \u043f\u043e \u0432\u044b\u0437\u043e\u0432\u0430\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u044d\u0442\u0438\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435 \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f.<\/i>  <\/div>\n<\/div>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430 \u0443\u043c\u043d\u044b\u0445 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b\u0430\u0441\u044c \u0440\u044f\u0434\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432: \u00ab\u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c \u2014 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u2014 \u0433\u043b\u044f\u043d\u0443\u043b\u0438, \u0447\u0442\u043e\u0431\u044b reatin\/release \u043f\u0440\u043e\u0448\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u00bb. \u0422\u0435\u0441\u0442\u044b (\u0447\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u043c) \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b\u0438. \u041a\u043e\u0434 \u043d\u0430 \u0443\u043c\u043d\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u044f \u043f\u0435\u0440\u0435\u0432\u0451\u043b \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u044f\u043d\u0432\u0430\u0440\u044f \u0438\u2026 \u0434\u0430, \u0442\u043e\u0433\u0434\u0430 \u0432\u0441\u0451 \u0442\u043e\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e.<\/p>\n<p>  \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0430\u0447\u0430\u043b\u0438\u0441\u044c \u043c\u0435\u0441\u044f\u0446 \u043d\u0430\u0437\u0430\u0434, \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043f\u0430\u043c\u044f\u0442\u044c, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u0430\u044f \u0443\u043c\u043d\u044b\u043c\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438, \u0443\u0434\u0430\u043b\u044f\u043b\u0430\u0441\u044c \u0440\u0430\u043d\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<p>  \u041f\u043e\u044f\u0441\u043d\u044e \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435:<\/p>\n<pre><code class=\"cpp\">DStrongReference&lt;DPlugIn&gt; DPlugInManager::createPlugIn( \t\tconst DPlugInDescriptor &inDescriptor) { . . .  \tDStrongReference&lt;DPlugIn&gt; thePlugInReference = \t\t\tinternalCreatePlugIn(inDescriptor); . . .  \treturn thePlugInReference; }  ...  DStrongReference&lt;DPlugIn&gt; DPlugInManager::internalCreatePlugIn( \t\tconst DPlugInDescriptor &inDescriptor) { \tfor (IDPlugInStorage *thePlugInStorage : _storages) { \t\tif (thePlugInStorage-&gt;getPlugInStatus(inDescriptor)) \t\t\treturn thePlugInStorage-&gt;createPlugIn(inDescriptor); \t} \treturn DStrongReference&lt;DPlugIn&gt;(); }  ...  class DPlugInStorageImpl : public IDPlugInStorage { public: \tvirtual ~DPlugInStorageImpl() { }  \tvirtual DStrongReference&lt;DPlugIn&gt; createPlugIn( \t\t\tconst DPlugInDescriptor &inDescriptor); }; <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <i>DPlugInStorageImpl::createPlugIn(&#8230;)<\/i> \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0447\u0435\u0440\u0435\u0437 <i>DStrongReference<\/i>, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u044d\u0442\u043e\u0442 \u0443\u043c\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 <i>DPlugInManager::internalCreatePlugIn(&#8230;)<\/i> \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u2014 \u043c\u0435\u0442\u043e\u0434 <i>DPlugInManager::createPlugIn(&#8230;)<\/i>.<\/p>\n<p>  \u0422\u0430\u043a \u0432\u043e\u0442, \u043a\u043e\u0433\u0434\u0430 \u0443\u043c\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434 <i>DPlugInManager::createPlugIn(&#8230;)<\/i>, <i>thePlugInReference<\/i> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043d\u0430 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0434\u0435\u043b\u043e \u0431\u044b\u043b\u043e \u0432 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 retain\/release-\u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u041f\u043e\u0442\u0440\u0430\u0442\u0438\u0432 \u043a\u0443\u0447\u0443 \u043d\u0435\u0440\u0432\u043e\u0432 \u0441 \u0434\u0435\u0431\u0430\u0433\u0433\u0435\u0440\u043e\u043c \u0432 Eclipse (\u043a \u0441\u043b\u043e\u0432\u0443 \u2014 \u043e\u043d \u0443\u0436\u0430\u0441\u0435\u043d), \u044f \u043f\u043b\u044e\u043d\u0443\u043b, \u0438 \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043f\u043e-\u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043b\u043e\u0433. \u041f\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u043d\u0430 \u0432\u044b\u0437\u043e\u0432\u0430\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 retain \u0438 release \u0432\u044b\u0432\u043e\u0434, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443\u2026 \u0427\u0442\u043e \u044f \u043e\u0436\u0438\u0434\u0430\u043b \u0443\u0432\u0438\u0434\u0435\u0442\u044c? \u0412\u043e\u0442 \u0442\u0430\u043a\u043e\u0435 \u0447\u0442\u043e-\u0442\u043e (\u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434):<\/p>\n<p>  <i>DPlugInStorageImpl::createPlugIn(&#8230;) =&gt; RETAIN<br \/>  DPlugInManager::internalCreatePlugIn(&#8230;), return createPlugIn =&gt; RETAIN<br \/>  DPlugInStorageImpl::createPlugIn(&#8230;), ~DStrongReference() =&gt; RELEASE<br \/>  DPlugInManager::createPlugIn(&#8230;), thePlugInReference = internalCreatePlugIn(&#8230;) =&gt; RETAIN<br \/>  DPlugInManager::internalCreatePlugIn(&#8230;),~DStrongReference() =&gt; RELEASE<\/i><\/p>\n<p>  \u0418\u0442\u043e\u0433\u043e: <i>ref_count = 1<\/i> \u0434\u043b\u044f <i>thePlugInReference<\/i>. \u0412\u0441\u0451 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b\u0442\u044c \u0447\u0451\u0442\u043a\u043e.<\/p>\n<p>  \u0422\u043e, \u0447\u0442\u043e \u044f \u0443\u0432\u0438\u0434\u0435\u043b \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043b\u043e \u043c\u0435\u043d\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a (0_0) \u0438 \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 <s>\u043f\u043e\u043b\u0442\u043e\u0440\u0430 \u0447\u0430\u0441\u0430<\/s> \u043f\u044f\u0442\u044c \u043c\u0438\u043d\u0443\u0442 \u043d\u0430 \u0432\u0441\u044f\u043a\u0438\u0435 clean-up, \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0444\u043b\u0430\u0448\u0438\u0442\u044c stdout \u0438 \u043f\u0440\u043e\u0447.<\/p>\n<p>  <i>DPlugInStorageImpl::createPlugIn(&#8230;) =&gt; RETAIN<br \/>  DPlugInManager::internalCreatePlugIn(&#8230;),~DStrongReference() =&gt; RELEASE<\/i><\/p>\n<p>  \u041e\u0442\u0447\u0430\u044f\u0432\u0448\u0438\u0441\u044c \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0432 \u0431\u043e\u0435\u0432\u043e\u043c \u043a\u043e\u0434\u0435 \u0438 \u0443\u0436\u0435 \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u044f \u0447\u0442\u043e-\u0442\u043e \u043a\u0440\u0430\u0439\u043d\u0435 \u043d\u0435\u043b\u0430\u0434\u043d\u043e\u0435, \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<h3>2. \u0422\u0435\u0441\u0442<\/h3>\n<p>  \u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream&gt; #include &lt;stdio.h&gt;  class TestClass { private: \tint _state;  public: \tTestClass(int inState) : _state(inState) { std::cout &lt;&lt; &quot;State based: &quot; &lt;&lt; inState &lt;&lt; std::endl; }  \tTestClass() : _state(1) { std::cout &lt;&lt; &quot;Default&quot; &lt;&lt; std::endl; }  \tTestClass(const TestClass &inObject0) : _state(2) { std::cout &lt;&lt; &quot;Const Copy&quot; &lt;&lt; std::endl; } \tTestClass(TestClass &inObject0) : _state(3) { std::cout &lt;&lt; &quot;Copy&quot; &lt;&lt; std::endl; }  \tTestClass(const TestClass &&inObject0) : _state(4) { std::cout &lt;&lt; &quot;Const Move&quot; &lt;&lt; std::endl; } \tTestClass(TestClass &&inObject0) : _state(5) { std::cout &lt;&lt; &quot;Move&quot; &lt;&lt; std::endl; }  \t~TestClass() { std::cout &lt;&lt; &quot;Destroy&quot; &lt;&lt; std::endl; }  \tvoid call() { std::cout &lt;&lt; &quot;Call &quot; &lt;&lt; _state &lt;&lt; std::endl; } };  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ int main() { \tTestClass theTestObject = TestClass(); \ttheTestObject.call(); \tfflush(stdout); \treturn 0; } <\/code><\/pre>\n<p>  \u041e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <i>Default<br \/>  Const Copy<br \/>  Call 1<br \/>  Destroy<\/i><\/p>\n<p>  \u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <i>Default<br \/>  Call 1<br \/>  Destroy<\/i><\/p>\n<p>  \u0422\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u043f\u0438-\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0441\u044f. \u0418 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430 \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u0442\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443. \u0417\u0430\u0433\u0443\u0433\u043b\u0438\u043b \u0438 \u0443\u0437\u043d\u0430\u043b \u043f\u0440\u043e <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/copy_elision\">copy_elision<\/a>.<\/p>\n<h3>3. \u0421\u0442\u0440\u0430\u0448\u043d\u0430\u044f \u043f\u0440\u0430\u0432\u0434\u0430<\/h3>\n<p>  \u0412 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445 \u2014 \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0421++ \u043c\u043e\u0436\u0435\u0442 \u0431\u0435\u0437 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u0438 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0444\u043b\u0430\u0433\u043e\u0432 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432 copy-\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f <s>\u0431\u0435\u0437 \u0445\u0430\u043a\u043e\u0432<\/s> \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u043d\u0435\u043b\u044c\u0437\u044f. \u0412\u043e\u0442 <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/copy_elision\">\u0442\u0443\u0442<\/a> \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 Notes \u043f\u0440\u044f\u043c\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e: &quot;<a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%AD%D0%BB%D0%B8%D0%B7%D0%B8%D1%8F\">\u042d\u043b\u0438\u0437\u0438\u044f<\/a> \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u044b\u0439 \u0432\u0438\u0434 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b&quot;, <i>\u00abCopy elision is the only allowed form of optimization that can change the observable side-effects\u00bb<\/i>.<\/p>\n<p>  \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u2014 \u044d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u2026 \u041d\u043e \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u043d\u0435 <i>\u043d\u0443\u0436\u043d\u043e<\/i> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0443\u043c\u043d\u044b\u0445 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439? \u0418 \u0447\u0442\u043e \u043c\u043d\u0435 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u0443\u044e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0438 <i>-o1<\/i> \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432 \u0442\u0435\u043b\u0435 copy-\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438?.. \u0414\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u0441\u0438\u0435 \u043c\u043d\u0435 \u043d\u0435 \u044f\u0441\u043d\u043e.<\/p>\n<h3>4. \u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u042f \u043d\u0430\u0448\u0451\u043b \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<p>  1) \u0427\u0435\u0440\u0435\u0437 \u0444\u043b\u0430\u0433\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u041f\u043b\u043e\u0445\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f g++ \u043d\u0443\u0436\u043d\u043e \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0444\u043b\u0430\u0433 <i>-fno-elide-constructors<\/i>, \u0438 \u044d\u0442\u043e \u043b\u0438\u0431\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0432\u0435\u0441\u044c \u043f\u0440\u043e\u0435\u043a\u0442 (\u0447\u0442\u043e \u0443\u0436\u0430\u0441\u043d\u043e), \u043b\u0438\u0431\u043e \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 push\/pop \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0444\u043b\u0430\u0433\u043e\u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0447\u0442\u043e \u0437\u0430\u0433\u0440\u043e\u043c\u043e\u0436\u0434\u0430\u0435\u0442 \u043a\u043e\u0434 \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u043c\u0435\u043d\u0435\u0435 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440).<\/p>\n<p>  2) \u0427\u0435\u0440\u0435\u0437 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/explicit\">explicit<\/a>. \u042d\u0442\u043e \u0442\u043e\u0436\u0435 \u043f\u043b\u043e\u0445\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431, \u043d\u043e, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u044d\u0442\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u043b\u0430\u0433\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<br \/>  \u0421\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 explicit \u043d\u0443\u0436\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u043d\u0435\u044f\u0432\u043d\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u0447\u0435\u0440\u0435\u0437 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432. \u0422\u043e \u0435\u0441\u0442\u044c, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u043c\u0435\u0441\u0442\u043e <i>MyInt theMyInt = 1<\/i> \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c <i>MyInt theMyInt = MyInt(1)<\/i>.<br \/>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0441\u043b\u043e\u0432\u043e \u043f\u0435\u0440\u0435\u0434 copy-\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u0435\u0442 \u043d\u0435\u044f\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u2014 \u0437\u0430\u043f\u0440\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043a \u0441\u0432\u043e\u0435\u043c\u0443 \u0442\u0438\u043f\u0443.<\/p>\n<p>  \u0422\u0430\u043a\u043e\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;iostream&gt; #include &lt;stdio.h&gt;  class TestClass { private: \tint _state;  public: \tTestClass(int inState) : _state(inState) { std::cout &lt;&lt; &quot;State based: &quot; &lt;&lt; inState &lt;&lt; std::endl; }  \tTestClass() : _state(1) { std::cout &lt;&lt; &quot;Default&quot; &lt;&lt; std::endl; } \texplicit TestClass(const TestClass &inObject0) : _state(2) { std::cout &lt;&lt; &quot;Const Copy&quot; &lt;&lt; std::endl; } }  \t~TestClass() { std::cout &lt;&lt; &quot;Destroy&quot; &lt;&lt; std::endl; }  \tvoid call() { std::cout &lt;&lt; &quot;Call &quot; &lt;&lt; _state &lt;&lt; std::endl; } };  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ int main() { \tTestClass theTestObject = TestClass(); \ttheTestObject.call(); \tfflush(stdout); \treturn 0; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0443 \u043c\u0435\u043d\u044f (g++ 4.6.1) \u0432\u044b\u0437\u0432\u0430\u043b \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<p>  <i>error: no matching function for call to &#8216;TestClass::TestClass(TestClass)&#8217;<\/i><\/p>\n<p>  \u0427\u0442\u043e \u0435\u0449\u0451 \u0437\u0430\u0431\u0430\u0432\u043d\u0435\u0435, \u0438\u0437-\u0437\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0421++ \u0432\u043e\u0442 \u0442\u0430\u043a: TestClass theTestObject(TestClass()) \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u043e\u0436\u0435 \u043d\u0435 \u0432\u044b\u0439\u0434\u0435\u0442, \u0432\u0435\u0434\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<p>  <i>error: request for member &#8216;call&#8217; in &#8216;theTestObject&#8217;, which is of non-class type &#8216;TestClass(TestClass (*)())&#8217;<\/i><\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u043b\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440.<\/p>\n<p>  \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e \u0434\u043b\u044f \u043c\u0435\u043d\u044f, \u0442\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u043e\u0448\u043b\u043e. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044f \u0432\u044b\u043d\u0443\u0434\u0438\u043b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0441 \u0442\u0435\u043c\u0438 \u0436\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0447\u0442\u043e \u0438 \u0443 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0422\u043e \u0435\u0441\u0442\u044c \u044d\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u00ab\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a \u0441\u0432\u043e\u0435\u043c\u0443 \u0442\u0438\u043f\u0443\u00bb, \u0430 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u00ab\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a \u0442\u0438\u043f\u0443, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0435 \u0436\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b\u00bb, \u0447\u0442\u043e \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434, \u043d\u043e \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u043e\u0442 \u0447\u0442\u043e \u0432\u044b\u0448\u043b\u043e<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">template&lt;typename T_Type, typename T_Holding, typename T_Access&gt; class DReference {  . . . \tIDSharedMemoryHolder *_holder;  \tvoid retain(IDSharedMemoryHolder *inHolder) { . . . } \tvoid release() { . . . }   . . .  \t~DReference() { release(); }  \t\/\/NB: Workaround for Copy elision \texplicit DReference( \t\t\tconst OwnType &inLReference) \t\t\t\t\t: _holder(NULL), _holding(), _access() \t{ \t\t\/\/ Call for some magic cases \t\tretain(inLReference._holder); \t}  \ttemplate&lt;typename T_OtherType, \t\t\ttypename T_OtherHolding, \t\t\ttypename T_OtherAccess&gt; \tDReference( \t\t\tconst DReference&lt;T_OtherType, T_OtherHolding, T_OtherAccess&gt; & \t\t\t\t\tinLReference) : _holder(NULL), _holding(), _access() \t{ \t\tretain(inLReference._holder); \t}  . . .   } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0430\u043d\u0430\u043b\u043e\u0433 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0441\u0442\u044b\u043b\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0431\u044b \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;iostream&gt; #include &lt;stdio.h&gt;  class TestClass { private: \tint _state;  public: \tTestClass(int inState) : _state(inState) { std::cout &lt;&lt; &quot;State based: &quot; &lt;&lt; inState &lt;&lt; std::endl; }  \tTestClass() : _state(1) { std::cout &lt;&lt; &quot;Default&quot; &lt;&lt; std::endl; } \texplicit TestClass(const TestClass &inObject0) : _state(2) { std::cout &lt;&lt; &quot;Const Copy&quot; &lt;&lt; std::endl; }  \ttemplate&lt;typename T&gt; \tTestClass(const T &inObject0) : _state(13) { std::cout &lt;&lt; &quot;Template Copy&quot; &lt;&lt; std::endl; }  \t~TestClass() { std::cout &lt;&lt; &quot;Destroy&quot; &lt;&lt; std::endl; }  \tvoid call() { std::cout &lt;&lt; &quot;Call &quot; &lt;&lt; _state &lt;&lt; std::endl; } };  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ int main() { \tTestClass theTestObject = TestClass(); \ttheTestObject.call(); \tfflush(stdout); \treturn 0; } <\/code><\/pre>\n<p>  \u0422\u0430 \u0436\u0435 \u0444\u0438\u0448\u043a\u0430. \u0421\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430, \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0449\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\u2026 \u0422\u0443\u0442 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0432\u0435\u0434\u044c \u043c\u044b \u043d\u0435 \u043a \u043c\u0435\u0441\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u044b. \u0415\u0441\u043b\u0438 \u043a\u0442\u043e \u0437\u043d\u0430\u0435\u0442 \u043a\u0430\u043a \u043b\u0443\u0447\u0448\u0435 \u2014 \u043e\u0442\u043f\u0438\u0448\u0438\u0442\u0435\u0441\u044c.  <\/div>\n<\/div>\n<h3>\u0412\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/h3>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043e <i>copy elision<\/i> \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u043e\u0434\u0430 \u0442\u0440\u0438 \u0432 \u0421++ \u0438 \u043e\u043a\u043e\u043b\u043e-\u0421++ \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435, \u043e\u043d\u0438 <s>\u0442\u043e\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432\u043e\u0442 \u0442\u0430\u043a (0_0)<\/s> \u0443\u0434\u0438\u0432\u0438\u043b\u0438\u0441\u044c \u043d\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u043c\u043e\u0435\u0433\u043e. \u041c\u0435\u0436\u0434\u0443 \u0442\u0435\u043c, \u0434\u0430\u043d\u043d\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0435 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430, \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0421++ \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439.<\/p>\n<p>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0438 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u0447\u044c\u0451-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>  <i>\u041f.\u0421.: \u041f\u0438\u0448\u0438\u0442\u0435 \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u0437\u0430\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u043b\u043e\u0448\u043d\u043e\u0441\u0442\u0435\u0439 \u2014 \u0431\u0443\u0434\u0443 \u043f\u0440\u0430\u0432\u0438\u0442\u044c.<\/i> \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/252885\/\"> http:\/\/habrahabr.ru\/post\/252885\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p> \t\t\t<img decoding=\"async\" src=\"http:\/\/hsto.org\/files\/ebb\/f65\/6bd\/ebbf656bda4946a9b2dd9449f4b31dc1.png\"\/><\/p>\n<p>  \u0423\u0436\u0435 \u0433\u043e\u0434 \u0432 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0435 \u043e\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0440\u0435\u043c\u044f \u044f \u043f\u0438\u043b\u044e \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u0441\u043c\u0435\u0441\u0438 Maven \u0438 Spring \u0434\u043b\u044f \u0421++. \u0412\u0430\u0436\u043d\u043e\u0439 \u0435\u0451 \u0447\u0430\u0441\u0442\u044c\u044e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A3%D0%BC%D0%BD%D1%8B%D0%B9_%D1%83%D0%BA%D0%B0%D0%B7%D0%B0%D1%82%D0%B5%D0%BB%D1%8C\">\u0443\u043c\u043d\u044b\u0445 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439<\/a>. \u0417\u0430\u0447\u0435\u043c \u043c\u043d\u0435 \u0432\u0441\u0451 \u044d\u0442\u043e \u2014 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0435\u043c\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u0434\u043d\u0430, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0444\u0438\u0447\u0430 \u0421++ \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043b\u0430 \u043c\u0435\u043d\u044f \u0443\u0441\u043e\u043c\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0437\u0434\u0440\u0430\u0432\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430.  <\/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-252929","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/252929","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=252929"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/252929\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=252929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=252929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=252929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}