{"id":375589,"date":"2024-05-21T06:28:14","date_gmt":"2024-05-21T06:28:14","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=375589"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T06:28:14","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=375589","title":{"rendered":"<span>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u043a\u0430 qdEngine, \u0447\u0430\u0441\u0442\u044c \u0432\u0442\u043e\u0440\u0430\u044f: \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0435 C++ \u043a\u043e\u0434\u0430<\/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\/0e\/sw\/0v\/0esw0vk6fr6cuva3tmxoenbkjts.png\" alt=\"\u0418\u0449\u0435\u043c \u0431\u0430\u0433\" data-src=\"https:\/\/habrastorage.org\/webt\/0e\/sw\/0v\/0esw0vk6fr6cuva3tmxoenbkjts.png\"\/><br \/>  \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 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 PVS-Studio \u0432\u043e\u043e\u0434\u0443\u0448\u0435\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u043e\u043c \u043a\u043e\u0434\u0430. \u0412\u0435\u0434\u044c \u0447\u0435\u043c \u043a\u043e\u0440\u043e\u0447\u0435, \u043f\u0440\u043e\u0449\u0435 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435 \u043a\u043e\u0434, \u0442\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0432 \u043d\u0451\u043c \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 &#171;<a href=\"https:\/\/habr.com\/ru\/companies\/pvs-studio\/articles\/810987\/\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u043a\u0430 qdEngine, \u0447\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u0430\u044f: \u0442\u043e\u043f 10 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439 PVS-Studio<\/a>&#187; \u043c\u044b \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u043a\u043e\u0434\u0430, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u043e\u0434\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u043e \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 PVS-Studio (\u0441\u043c. \u0434\u0435\u0441\u044f\u0442\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u043a\u0430\u043a \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u043e\u0434 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430.<\/p>\n<p>  <\/p>\n<h2 id=\"pereuslozhnyonnaya-funkciya-restore\">\u041f\u0435\u0440\u0435\u0443\u0441\u043b\u043e\u0436\u043d\u0451\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f restore<\/h2>\n<p>  <\/p>\n<pre><code class=\"cpp\">class qdCamera  {   ....   sGridCell *Grid;   .... };  bool qdCamera::restore(sGridCell *grid,                        int sx, int sy,                        int csx, int csy) {   if (Grid)     delete[] Grid;   Grid  = new sGridCell[sx * sy];   if (!Grid)     return false;   memcpy(Grid, grid, sizeof(sGridCell) * sx * sy);    GSX = sx;   GSY = sy;   cellSX = csx;   cellSY = csy;    return true; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u0435\u0440\u0435\u0432\u044b\u0434\u0435\u043b\u044f\u044e\u0449\u0430\u044f \u0431\u0443\u0444\u0435\u0440 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430. \u0410\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u0438\u0434\u0438\u0442 \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <em>new[]<\/em>. \u0420\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e\u0431 \u044d\u0442\u0438\u0445 \u0441\u0442\u0440\u043e\u043a\u0430\u0445:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">Grid  = new sGridCell[sx * sy]; if (!Grid)   return false;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 PVS-Studio: <a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v668\/\">V668<\/a> There is no sense in testing the &#8216;Grid&#8217; pointer against null, as the memory was allocated using the &#8216;new&#8217; operator. The exception will be generated in the case of memory allocation error. qd_camera.cpp 910<\/p>\n<p>  <\/p>\n<p>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0435\u0441\u043b\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0430\u043c\u044f\u0442\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432, \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <em>new[]<\/em> \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <em><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/memory\/new\/bad_alloc\">std::bad_alloc<\/a><\/em>. \u041d\u0443\u043b\u0435\u0432\u043e\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <em><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/memory\/new\/nothrow\">new (std::nothrow) []<\/a><\/em>, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u043d\u0430\u0448 \u0441\u043b\u0443\u0447\u0430\u0439.<\/p>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0443\u0434\u0430\u043b\u0438\u043b\u0438 \u043b\u0438\u0448\u043d\u044e\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">bool qdCamera::restore(sGridCell *grid,                        int sx, int sy,                        int csx, int csy) {   if (Grid)     delete[] Grid;   Grid = new sGridCell[sx * sy];   memcpy(Grid, grid, sizeof(sGridCell) * sx * sy);    GSX = sx;   GSY = sy;   cellSX = csx;   cellSY = csy;    return true; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>restore<\/em> \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <em>true<\/em>. \u041e\u043d\u0430 \u0438\u043b\u0438 \u043a\u0438\u0434\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0438\u043b\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442. \u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b (<em>true<\/em> \u0438\u043b\u0438 <em>false<\/em>). \u041c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0443\u0431\u0440\u0430\u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void qdCamera::restore(sGridCell *grid,                        int sx, int sy,                        int csx, int csy) {   if (Grid)     delete[] Grid;   Grid  = new sGridCell[sx * sy];   memcpy(Grid, grid, sizeof(sGridCell) * sx * sy);    GSX = sx;   GSY = sy;   cellSX = csx;   cellSY = csy; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0431\u043e\u043d\u0443\u0441: \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0447\u0442\u043e \u0432\u0435\u0440\u043d\u0443\u043b\u0430 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c? \u041d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <em>delete[]<\/em>. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 (\u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435).<\/p>\n<p>  <\/p>\n<p>\u041a\u0442\u043e-\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0440\u0430\u0437\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u2014 \u044d\u0442\u043e \u043c\u0438\u043a\u0440\u043e\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0443\u043b\u0435\u0432\u043e\u0439, \u0442\u043e \u043d\u0435 \u043d\u0430\u0434\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440. \u042d\u0442\u043e \u0433\u043b\u0443\u043f\u043e\u0441\u0442\u044c. \u0412\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043d\u0435\u0431\u0440\u0435\u0447\u044c \u043d\u0430 \u0444\u043e\u043d\u0435 \u0442\u0430\u043a\u0438\u0445 \u0442\u044f\u0436\u0435\u043b\u043e\u0432\u0435\u0441\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043a\u0430\u043a \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438. \u042f \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u043b \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 &#171;<a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/1100\/\">\u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 NULL \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 free?<\/a>&#171;. \u041a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u0442\u0430\u043c \u043f\u0440\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>free<\/em>, \u043d\u043e \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <em>delete<\/em> \u0432\u0441\u0451 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void qdCamera::restore(sGridCell* grid,                        int sx, int sy,                        int csx, int csy) {   delete[] Grid;   Grid = new sGridCell[sx*sy];   memcpy(Grid, grid, sizeof(sGridCell) * sx * sy);    GSX = sx;   GSY = sy;   cellSX = csx;   cellSY = csy; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0438 \u043a\u043e\u0434, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u0432. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0438 \u0441\u0442\u0430\u0440\u044b\u0439, \u0438 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0438\u043c\u0435\u044e\u0442 \u0441\u043b\u0430\u0431\u043e\u0435 \u043c\u0435\u0441\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">delete[] Grid; Grid = new sGridCell[sx * sy]; .... qdCamera::~qdCamera() {   if (GSX)   {     delete[] Grid;   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <em>new<\/em> \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u043d\u0430\u0447\u043d\u0451\u0442\u0441\u044f \u0440\u0430\u0441\u043a\u0440\u0443\u0442\u043a\u0430 \u0441\u0442\u0435\u043a\u0430 \u0438 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0412 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f \u0438 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441\u0430\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <em>qdCamera<\/em>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c <em>Grid<\/em> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u043d\u0443\u043b\u0435\u0432\u044b\u043c, \u043d\u043e \u0443\u0436\u0435 \u0438 \u043d\u0435 \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c. \u041c\u0430\u0441\u0441\u0438\u0432 \u0431\u044b\u043b \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d \u043a\u0430\u043a \u0440\u0430\u0437 \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <em>new<\/em>. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u0430\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043f\u0440\u0430\u0432\u043a\u0430 \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u043d\u0443\u043b\u0435\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">delete[] Grid; Grid = nullptr; Grid = new sGridCell[sx * sy];<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u043b\u043e\u0445\u0430\u044f \u043f\u0440\u0430\u0432\u043a\u0430. \u041d\u0430\u0448\u0430 \u044d\u043d\u0435\u0440\u0433\u0438\u044f \u0443\u0445\u043e\u0434\u0438\u0442 \u043d\u0435 \u0442\u0443\u0434\u0430. \u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e. \u041e\u043d\u043e \u043f\u0440\u043e\u0432\u043e\u0446\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0434\u043b\u0438\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043b\u0435\u0433\u043a\u043e \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u043c\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0438\u043b\u0438 <em>std::vector<\/em>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u0443\u043c\u043d\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f <em><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/memory\/unique_ptr\">std::unique_ptr<\/a><\/em>, \u0442\u0430\u043a \u043a\u0430\u043a <em><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/container\/vector\">std::vector<\/a><\/em> \u0443\u0434\u043e\u0431\u0435\u043d \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d \u043d\u0435 \u0432\u043e \u0432\u0441\u0435\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445.<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">class qdCamera {   ....   std::unique_ptr&lt;sGridCell[]> Grid;   ~qdCamera() = default;   .... };  void qdCamera::restore(sGridCell *grid,                        int sx, int sy,                        int csx, int csy) {   Grid = std::make_unique&lt;sGridCell[]>(sx * sy);   std::copy(grid, grid + sx * sy, Grid.get());    GSX = sx;   GSY = sy;   cellSX = csx;   cellSY = csy; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0440\u0430\u0441\u043e\u0442\u0430:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041a\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043b \u043a\u043e\u0440\u043e\u0447\u0435;<\/li>\n<li>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0443\u043c\u043d\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e \u0438 <em>std::make_unique<\/em> \u043c\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u0437\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u043e\u0442 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <em>new<\/em>\/<em>delete<\/em>.<\/li>\n<li>\u041a\u043e\u0434 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u0435\u043d;<\/li>\n<li>\u0414\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <em>std::vector<\/em>.<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">class qdCamera {   ....   std::vector&lt;sGridCell> Grid;   ~qdCamera() = default;   .... };  void qdCamera::restore(sGridCell *grid,                        int sx, int sy,                        int csx, int csy) {   Grid.clear();   Grid.reserve(sx * sy);   std::copy(grid, grid + sx * sy, std::back_inserter(Grid));    GSX = sx;   GSY = sy;   cellSX = csx;   cellSY = csy; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b, \u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043c\u043d\u043e\u0433\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0421 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>restore<\/em> \u0441\u0442\u0430\u043d\u0435\u0442 \u0442\u0430\u043a\u043e\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void qdCamera::restore(const std::vector&lt;sGridCell> &amp;grid,                        int sx, int sy,                        int csx, int csy) {   Grid = grid;   GSX = sx;   GSY = sy;   cellSX = csx;   cellSY = csy; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u044f \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u0434\u0430\u043b\u044f\u044e\u0441\u044c \u043e\u0442 \u0441\u0443\u0442\u0438 \u043f\u043e\u0432\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u0448\u0438\u0440\u043d\u043e\u0433\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0432\u043e\u043e\u0431\u0449\u0435 \u0434\u0440\u0443\u0433\u0438\u043c, \u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>restore<\/em>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0441\u0447\u0435\u0437\u043d\u0443\u0442\u044c \u0438\u043b\u0438 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e \u0447\u0442\u043e-\u0442\u043e \u0438\u043d\u043e\u0435.<\/p>\n<p>  <\/p>\n<p>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043c\u044b\u0441\u043b\u044c: \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 PVS-Studio \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<p>  <\/p>\n<h2 id=\"upravlenie-pamyatyu-v-stile-yazyka-c-v-klasse-arbutton\">\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 \u0441\u0442\u0438\u043b\u0435 \u044f\u0437\u044b\u043a\u0430 C \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 arButton<\/h2>\n<p>  <\/p>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0435 <em>arButton<\/em> \u0440\u0443\u0447\u043d\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u043e \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u044f\u0440\u043a\u043e, \u0447\u0435\u043c \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435. \u041a\u043b\u0430\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043a\u043e\u043f\u0438\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043d\u0438\u0445.<\/p>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043f\u0438\u0439 \u0441\u0442\u0440\u043e\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">class arButton {   ....   void set_obj(const char* p)     { if(obj_name) free(obj_name);       obj_name = strdup(p); }   void set_obj_regvalue(const char* p)     { if(obj_name_regvalue) free(obj_name_regvalue);       obj_name_regvalue = strdup(p); }   void set_cmdline(const char* p)     { if(cmd_line) free(cmd_line); cmd_line = strdup(p); }   void set_regkey(const char* p)     { if(reg_key) free(reg_key); reg_key = strdup(p); }   void set_reg_exec_path(const char* p)     { if(reg_exec_path_value) free(reg_exec_path_value);       reg_exec_path_value = strdup(p); }   void set_checkstr(const char* p)     { if(check_after_exec) free(check_after_exec);        check_after_exec = strdup(p); }   ....   char *obj_name;   char *obj_name_regvalue;   char *cmd_line;   char *reg_key;   char *reg_exec_path_value;   char *check_after_exec; };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439 &#171;get&#187;, \u043d\u043e \u043e\u043d\u0438 \u043d\u0430\u043c \u043f\u043e\u043a\u0430 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">char* get_obj(void) { return obj_name; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0440\u0443\u0433\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0448\u0435\u0441\u0442\u044c\u044e \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u043c\u0438 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u0440\u043e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0443\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438. \u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 PVS-Studio, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0437\u0430\u0433\u0440\u043e\u043c\u043e\u0436\u0434\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e: <a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v773\/\">V773<\/a> The &#8216;obj_name&#8217; pointer was not released in destructor. A memory leak is possible. ar_button.cpp 50<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0451 \u0434\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442.<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">arButton::~arButton(void) { }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em><a href=\"https:\/\/en.cppreference.com\/w\/c\/experimental\/dynamic\/strdup\">strdup<\/a><\/em> \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 <em>set_*<\/em> \u043d\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u044e\u0442\u0441\u044f. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0443\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u043d\u0438\u0442\u044c \u043a\u043e\u0434, \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u043d\u043e \u043d\u0435\u0442 \u0434\u0430\u0436\u0435 \u0436\u0435\u043b\u0430\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0448\u0430\u0433. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u043e\u0434 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u043d\u043e \u0438 \u0441\u0440\u0430\u0437\u0443 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0435\u0449\u0451 \u0440\u0430\u0437 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u0434\u043d\u0443 \u0438\u0437 set-\u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void set_obj(const char* p)   { if(obj_name) free(obj_name);     obj_name = strdup(p); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043b\u0430\u0431\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c <em>free<\/em> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/1100\/\">\u043b\u0438\u0448\u043d\u0435\u0439<\/a>. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <em>free<\/em> \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u0435\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c <em>NULL<\/em>.<\/li>\n<li>\u041d\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>strdup<\/em>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0435\u0440\u0435\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043e\u0434. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u043e\u0432\u043d\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>get_*<\/em> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <em>NULL<\/em>. \u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430. \u041f\u0435\u0440\u0432\u044b\u0439: \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>set_*<\/em> \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0430\u0441\u044c. \u0412\u0442\u043e\u0440\u043e\u0439: \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438, \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0430.<\/li>\n<li>\u041a\u0430\u043a \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e \u0432\u044b\u0448\u0435, \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441 \u0440\u0443\u0447\u043d\u044b\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u043f\u0440\u043e\u0432\u043e\u0446\u0438\u0440\u0443\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0443\u043c\u043d\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. \u041d\u043e \u044d\u0442\u043e \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <em>std::string<\/em>. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u043d\u0435 \u0437\u0440\u044f \u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0430 C++, \u0430 \u043d\u0435 \u043d\u0430 C.<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">class arButton {   ....   void set_obj(const char* p)           { obj_name = p; }   void set_obj_regvalue(const char* p)  { obj_name_regvalue = p; }   void set_cmdline(const char* p)       { cmd_line = p; }   void set_regkey(const char* p)        { reg_key = p; }   void set_reg_exec_path(const char* p) { reg_exec_path_value = p; }   void set_checkstr(const char* p)      { _after_exec = p; }   ....   std::string obj_name;   std::string obj_name_regvalue;   std::string cmd_line;   std::string reg_key;   std::string reg_exec_path_value;   std::string check_after_exec; };<\/code><\/pre>\n<p>  <\/p>\n<p>Get-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0430 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0431\u0443\u0434\u0443\u0442 \u0442\u0430\u043a\u0438\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">const char* get_obj(void) const { return obj_name.c_str(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043b\u0438 \u0442\u0430\u043a\u0438\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">const std::string&amp; get_obj(void) const { return obj_name; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a set-\u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c. \u041e\u043d\u0438 \u0435\u0449\u0451 \u043d\u0435 \u0434\u043e\u0432\u0435\u0434\u0435\u043d\u044b \u0434\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f &#171;\u0445\u043e\u0440\u043e\u0448\u043e&#187;, \u043d\u043e \u0431\u0435\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0443\u0436\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c, \u043a\u0430\u043a \u043b\u0443\u0447\u0448\u0435 \u0438\u0445 \u0434\u0430\u043b\u044c\u0448\u0435 \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c. \u041f\u043e\u043a\u0430 \u0443 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043a\u0430\u043a \u043b\u0443\u0447\u0448\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u0435\u0441\u043b\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d <em>nullptr<\/em>. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 &#171;\u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430&#187; \u0438\u043b\u0438 &#171;\u0431\u0435\u0434\u0430, \u0432\u0440\u0435\u043c\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435&#187;?<\/li>\n<li>\u041a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a \u043d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e. \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0431\u0443\u0444\u0435\u0440 \u043f\u043e\u0434 \u0441\u0442\u0440\u043e\u0447\u043a\u0443, \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0435\u0451 \u0434\u043b\u0438\u043d\u0443.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0433\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">.... void set_cmdline(std::string s) noexcept { cmd_line = std::move(s); } void set_regkey(std::string s)  noexcept { reg_key = std::move(s); } ....<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430 \u044d\u0442\u043e\u043c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f, \u0438\u043d\u0430\u0447\u0435 \u0434\u0430\u043b\u044c\u0448\u0435 \u0432\u0441\u0442\u0430\u043d\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u0430 \u043d\u0443\u0436\u043d\u0430 \u043b\u0438 \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u0430 \u0432 \u0432\u0438\u0434\u0435 get\/set-\u0444\u0443\u043d\u043a\u0446\u0438\u0439? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0443\u0436\u0435\u043d \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u0432\u0441\u0435\u043e\u0431\u044a\u0435\u043c\u043b\u044e\u0449\u0438\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433, \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<h2 id=\"poleznoe-dlya-opytnyh-programmistov\">\u041f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u0434\u043b\u044f \u043e\u043f\u044b\u0442\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432<\/h2>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0437\u0430\u0434\u0430\u0447\u0435\u043d\u044b \u0438 \u0434\u0443\u043c\u0430\u044e\u0442:<\/p>\n<p>  <\/p>\n<blockquote><p>&#171;\u0417\u0430\u0447\u0435\u043c \u0432\u0441\u0451 \u044d\u0442\u043e \u0431\u044b\u043b\u043e? \u0418 \u0442\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0440\u0443\u0447\u043d\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u2014 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e \u0438 \u043f\u0440\u043e\u0432\u043e\u0446\u0438\u0440\u0443\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438. \u0417\u0430\u0447\u0435\u043c \u0431\u044b\u043b\u043e \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440? \u0411\u0435\u0437 \u043d\u0435\u0433\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c&#187;.<\/p><\/blockquote>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u0435\u043d, \u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0434\u0432\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u0430:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0418\u043c\u0435\u043d\u043d\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043e\u0431\u0440\u0430\u0442\u0438\u043b \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u043b\u043e\u0445\u043e\u0439 \u043a\u043e\u0434.<\/li>\n<li>\u0415\u0441\u0442\u044c \u043f\u043e\u0432\u043e\u0434 \u043d\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u043e\u043c, \u0430 \u043f\u043e \u0434\u0435\u043b\u0443, \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u043e\u0448\u0438\u0431\u043a\u0438. \u041a\u043e\u043c\u0443 \u0432\u0435\u0447\u043d\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u2014 \u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u044d\u0442\u0438\u043c! \u041e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0432\u043e\u0434 \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0440\u0430\u0432\u043e\u043a: \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0438\/\u0441\u043b\u0430\u0431\u044b\u0435 \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u043a\u043e\u0434\u0430. \u041d\u0443 \u0430 \u0437\u0430\u043e\u0434\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0438 \u043f\u043e \u0441\u043e\u0441\u0435\u0434\u0441\u0442\u0432\u0443 \u043a\u0440\u0430\u0441\u043e\u0442\u0443 \u043d\u0430\u0432\u0435\u0441\u0442\u0438 \ud83d\ude42<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0439\u0442\u0435 <a href=\"https:\/\/pvs-studio.ru\/ru\/pvs-studio\/download\/?utm_source=website&amp;utm_medium=habr&amp;utm_campaign=article&amp;utm_content=1121\">PVS-Studio<\/a>, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u043b\u0443\u0447\u0448\u0435.<\/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\/1121\/\">Let&#8217;s check the qdEngine game engine, part two: simplifying C++ code<\/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\/812795\/\"> https:\/\/habr.com\/ru\/articles\/812795\/<\/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\/0e\/sw\/0v\/0esw0vk6fr6cuva3tmxoenbkjts.png\" alt=\"\u0418\u0449\u0435\u043c \u0431\u0430\u0433\" data-src=\"https:\/\/habrastorage.org\/webt\/0e\/sw\/0v\/0esw0vk6fr6cuva3tmxoenbkjts.png\"\/><br \/>  \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 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 PVS-Studio \u0432\u043e\u043e\u0434\u0443\u0448\u0435\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u043e\u043c \u043a\u043e\u0434\u0430. \u0412\u0435\u0434\u044c \u0447\u0435\u043c \u043a\u043e\u0440\u043e\u0447\u0435, \u043f\u0440\u043e\u0449\u0435 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435 \u043a\u043e\u0434, \u0442\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0432 \u043d\u0451\u043c \u043e\u0448\u0438\u0431\u043e\u043a.<\/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-375589","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375589","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=375589"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375589\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=375589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=375589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=375589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}