{"id":3806,"date":"2014-03-30T05:45:48","date_gmt":"2014-03-30T05:45:48","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/can-i-allocate-a-block-of-memory-with-new-collection-of-common-programming-errors\/"},"modified":"2014-03-30T05:45:48","modified_gmt":"2014-03-30T05:45:48","slug":"can-i-allocate-a-block-of-memory-with-new-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/can-i-allocate-a-block-of-memory-with-new-collection-of-common-programming-errors\/","title":{"rendered":"Can I Allocate a Block of Memory with new?-Collection of common programming errors"},"content":{"rendered":"<p>Is there any reason you want to do it like in the link you provided? A little more context would help. Otherwise I would personally just use a constructor to do that:<\/p>\n<pre><code>    struct myStruct {\n        int* arr1;\n        int* arr2;\n        myStruct(int num)\n        {\n                arr1 = new int[10];\n                arr2 = new int[10*num];\n        }\n        ~myStruct()\n        {\n                delete[] arr1;\n                delete[] arr2;\n        }\n};\n\nint main()\n{\n        int num = 3;\n        myStruct* a;\n        a = new myStruct(3);\n        delete a;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Is there any reason you want to do it like in the link you provided? A little more context would help. Otherwise I would personally just use a constructor to do that: struct myStruct { int* arr1; int* arr2; myStruct(int num) { arr1 = new int[10]; arr2 = new int[10*num]; } ~myStruct() { delete[] arr1; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3806","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3806","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3806"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3806\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}