{"id":98935,"date":"2018-06-07T07:00:00","date_gmt":"2018-06-07T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=98935"},"modified":"2019-03-13T00:41:50","modified_gmt":"2019-03-13T07:41:50","slug":"20180607-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20180607-00\/?p=98935","title":{"rendered":"What is this weird constructory syntax <CODE>C::C()<\/CODE>?"},"content":{"rendered":"<p>The Microsoft Visual C++ compiler supports this weird thing: <\/p>\n<pre>\n\/\/ assume a class C has been defined\nC* p = (C*)malloc(sizeof(C));\np-&gt;C::C(); \/\/ huh?\n<\/pre>\n<p>This weird syntax is how people in olden times explicitly invoked a constructor on an uninitialized block of memory. <\/p>\n<p>Then <a HREF=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/new\">placement new<\/a> arrived on the scene and made the above syntax obsolete. <\/p>\n<pre>\n\/\/ new hotness\nC* p = (C*)malloc(sizeof(C));\nnew(p) C();\n<\/pre>\n<p>But the Microsoft Visual C++ compiler still supports the old syntax for backward compatibility purposes. <\/p>\n<p>Note that the corresponding explicit destructor syntax <\/p>\n<pre>\np-&gt;C::~C(); \/\/ can be shortened to p-&gt;~C() if p is of type C*\n<\/pre>\n<p>is still standard as of this writing. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>An archaic syntax from ancient times.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-98935","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>An archaic syntax from ancient times.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/98935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=98935"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/98935\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=98935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=98935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=98935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}