{"id":2938,"date":"2018-05-21T20:00:34","date_gmt":"2018-05-21T18:00:34","guid":{"rendered":"https:\/\/mariusbancila.ro\/blog\/?p=2938"},"modified":"2018-05-23T15:00:51","modified_gmt":"2018-05-23T13:00:51","slug":"c-fun-strange-facts","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/","title":{"rendered":"C++ fun strange facts"},"content":{"rendered":"<p>The title might be a little bit misleading because, on one hand, you might not find these things funny if you are stumbling upon them and not understanding what is going on, and, on the other hand, they are not really strange when you pay attention to what is going on. However, here is a list of five (randomly picked) C++ features that would probably get you giving a second thought to what&#8217;s going on.<\/p>\n<h3>Aggregate initialization<\/h3>\n<p>Consider the following structure:<\/p>\n<pre class=\"lang:c++ decode:true \" >struct foo\r\n{\r\n   foo() {}\r\n};<\/pre>\n<p>You can write the following:<\/p>\n<pre class=\"lang:c++ decode:true \" >foo f1;\r\nfoo f2{};\r\nfoo f3[5];<\/pre>\n<p>But should you delete the default constructor as follows:<\/p>\n<pre class=\"lang:c++ default decode:true \" >struct foo\r\n{\r\n   foo() = delete;\r\n};<\/pre>\n<p>Then you can still intialize objects of this type but only using brace initialization (<tt>foo{}<\/tt>):<\/p>\n<pre class=\"lang:c++ decode:true \" >foo f1;     \/\/ error: attempting to reference a deleted function\r\nfoo f2{};\r\nfoo f3[5];  \/\/ error: attempting to reference a deleted function<\/pre>\n<p><tt>foo f;<\/tt> is no longer legal because <tt>foo<\/tt> does not have a default constructor anymore. However, <tt>foo f{};<\/tt> is still legal because classes with deleted default constructors can be list initialized via aggregate initialization but not value initialization. For more info see <a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/cwg_closed.html#1578\" rel=\"noopener\" target=\"_blank\">1578. Value-initialization of aggregates<\/a>.<\/p>\n<h3>Alternative function syntax gotchas<\/h3>\n<p>Alternative function syntax refers to putting the type of the return value of a function at the end after the function type, as in <tt>auto foo() noexcept -> int<\/tt>. However, it doesn&#8217;t always go as smooth as that. Let&#8217;s consider the the following base class:<\/p>\n<pre class=\"lang:c++ decode:true \" >struct B\r\n{\r\n   virtual int foo() const noexcept;\r\n};<\/pre>\n<p>How do you write an overriden <tt>foo()<\/tt> in a derived class using the trailing return type (aka alternative function syntax)? If you&#8217;re tempted to do it like this then you&#8217;re wrong.<\/p>\n<pre class=\"lang:c++ decode:true \" >struct D : B \r\n{\r\n   virtual auto foo() const noexcept override -&gt; int;\r\n};<\/pre>\n<p>This will generate a compiler error (which differes depending on your compiler). The reason is that <tt>override<\/tt> is not part of the function type, so it has to be written after the function type. In other words, the correct syntax is as follows:<\/p>\n<pre class=\"lang:c++ decode:true \" >struct D : B \r\n{\r\n   virtual auto foo() const noexcept -&gt; int override;\r\n};<\/pre>\n<p>For more pros and cons on using the alternative function syntax see this <a href=\"https:\/\/blog.petrzemek.net\/2017\/01\/17\/pros-and-cons-of-alternative-function-syntax-in-cpp\/\" rel=\"noopener\" target=\"_blank\">article<\/a>.<\/p>\n<h3>rvalue references and type deduction<\/h3>\n<p class=\"note-icon-lite\">I have updated this section to refer to universal references as forwarding references, as this is now the official term for these references, as noted by <a href=\"http:\/\/marcoarena.wordpress.com\/\" rel=\"noopener\" target=\"_blank\">Marco Arena<\/a>. For more, see <a href=\"https:\/\/blog.petrzemek.net\/2016\/09\/17\/universal-vs-forwarding-references-in-cpp\/\" rel=\"noopener\" target=\"_blank\">Universal vs Forwarding References in C++<\/a><\/p>\n<p>rvalue references are specified with <tt>&amp;&amp;<\/tt> but in type declaration <tt>&amp;&amp;<\/tt> could mean either rvalue reference or forwarding reference. The latter one is not a term that was preferred to universal reference, which was a term coined by Scott Meyers. It refers to a reference that can be either lvalue or rvalue. However, when you&#8217;re using &amp;&amp; as parameter in function (templates) the meaning of <tt>&amp;&amp;<\/tt> depends on whether type deduction is involved or not; if type deduction is involved, then it is an forwarding reference; otherwise, it is an rvalue reference. Here are some examples:<\/p>\n<pre class=\"lang:c++ decode:true \" >\r\nvoid foo(int&amp;&amp;);              \/\/ rvalue reference\r\n\r\ntemplate &lt;typename T&gt;\r\nvoid foo(T&amp;&amp;);                \/\/ forwarding reference\r\n\r\ntemplate &lt;typename T&gt;\r\nvoid foo(T const &amp;&amp;);         \/\/ rvalue reference;\r\n\r\ntemplate &lt;typename T&gt;\r\nvoid foo(std::vector&lt;T&gt;&amp;&amp;);   \/\/ rvalue reference\r\n\r\nstruct bar\r\n{\r\n   template &lt;typename T&gt;\r\n   void foo(T&amp;&amp;);             \/\/ forwarding reference\r\n};\r\n\r\ntemplate &lt;typename T&gt;\r\nstruct bar\r\n{\r\n   void foo(T&amp;&amp;);             \/\/ rvalue reference\r\n};\r\n\r\ntemplate &lt;typename T&gt;\r\nstruct bar\r\n{\r\n   template &lt;typename U&gt;\r\n   void foo(U&amp;&amp;);             \/\/ forwarding reference\r\n};\r\n<\/pre>\n<p>When you see something like <tt>T&amp;&amp;<\/tt> that means forwarding reference; however, if anything else is involved, like a const qualifier, such as in <tt>const T&amp;&amp;<\/tt>, then you have an rvalue reference. Also, if you have a <tt>std::vector&lt;T&gt;&amp;&amp;<\/tt> then you&#8217;re dealing with an rvalue reference. In this case, <tt>foo<\/tt> exists within the context of <tt>std::vector&lt;T&gt;<\/tt>, which means <tt>T<\/tt> is already known and does not have to be deduced.<\/p>\n<p>There is actually a long article about this topic by Scott Meyers called <a href=\"https:\/\/isocpp.org\/blog\/2012\/11\/universal-references-in-c11-scott-meyers\" rel=\"noopener\" target=\"_blank\">Universal References in C++11<\/a>. You should read it for a detailed look at the differences and caveats of rvalue and forwarding (aka universal) references. <\/p>\n<h3>std::array is not an array<\/h3>\n<p>Consider the following snippet:<\/p>\n<pre class=\"lang:c++ decode:true \" >int main()\r\n{\r\n   std::cout &lt;&lt; std::is_array_v&lt;int[5]&gt; &lt;&lt; std::endl;\r\n   std::cout &lt;&lt; std::is_array_v&lt;std::array&lt;int, 5&gt;&gt; &lt;&lt; std::endl;\r\n}\r\n<\/pre>\n<p>What do you expect this to print? Well, the answer is 1 and 0. If you&#8217;re surprised, then remember <tt>std::array<\/tt> is not an array, but a standard fixed-length container that has the same semantics as a struct holding a C-style array <tt>T[N]<\/tt> as its only non-static data member. And, unlike a C-like array, it doesn&#8217;t decay to <tt>T*<\/tt> automatically. On the other hand, <tt>std::is_array<\/tt> is conceptually defined as follows:<\/p>\n<pre class=\"lang:c++ decode:true \" >template&lt;class T&gt;\r\nstruct is_array : std::false_type {};\r\n \r\ntemplate&lt;class T&gt;\r\nstruct is_array&lt;T[]&gt; : std::true_type {};\r\n \r\ntemplate&lt;class T, std::size_t N&gt;\r\nstruct is_array&lt;T[N]&gt; : std::true_type {};<\/pre>\n<p>And that is why <tt>std::is_array&lt;std::array&lt;T, N&gt;&gt;<\/tt> is <tt>std::false_type<\/tt>.<\/p>\n<h3>Indexing arrays<\/h3>\n<p>I have to admit I only saw this a couple of times in my whole life, and although I don&#8217;t remember exactly where, it was problably some obfuscate code. The following is valid code:<\/p>\n<pre class=\"lang:c++ decode:true \" >int arr[5]{ 1,2,3,4,5 };\r\n1[arr] = 42;<\/pre>\n<p>This changes the second element of <tt>arr<\/tt> (at index 1) from 2 to 42. <tt>1[arr]<\/tt> is equivalent to <tt>arr[1]<\/tt>, which in turn is an alternative syntax for <tt>*(arr + 1)<\/tt>. Therefore, generally speaking, <tt>a[n]<\/tt> and <tt>n[a]<\/tt> are equivalent because the compiler would transform that expression in either <tt>*(a + n)<\/tt> or <tt>*(n + a)<\/tt>, which are equivalent. Therefore, all of these are valid and equivalent:<\/p>\n<pre class=\"lang:c++ decode:true \" >int arr[5]{ 1,2,3,4,5 };\r\n\r\narr[1] = 42;\r\n1[arr] = 42;\r\n*(arr + 1) = 42;<\/pre>\n<p>I think it could be possible for the compiler to differentiate and make constructs such as <tt>1[arr]<\/tt> illegal, but then again nobody actually indexes arrays like that, so I suppose it was never an issue.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The title might be a little bit misleading because, on one hand, you might not find these things funny if you are stumbling upon them and not understanding what is going on, and, on the other hand, they are not really strange when you pay attention to what is going on. However, here is a list of five (randomly picked) C++ features that would probably get you giving a second thought to what&#8217;s going on.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7],"tags":[451,125,556,74],"class_list":["post-2938","post","type-post","status-publish","format-standard","hentry","category-c","tag-c","tag-fun","tag-gotchas","tag-standard"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.3 - aioseo.com -->\n\t<meta name=\"description\" content=\"This article shows five random C++ constructs that you may find strange rather than intuitive.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"c++,gotchas,fun,standard\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.3\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"C++ fun strange facts\" \/>\n\t\t<meta property=\"og:description\" content=\"This article shows five random C++ constructs that you may find strange rather than intuitive.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2018-05-21T18:00:34+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2018-05-23T13:00:51+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"C++ fun strange facts\" \/>\n\t\t<meta name=\"twitter:description\" content=\"This article shows five random C++ constructs that you may find strange rather than intuitive.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/05\\\/21\\\/c-fun-strange-facts\\\/#article\",\"name\":\"C++ fun strange facts\",\"headline\":\"C++ fun strange facts\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"datePublished\":\"2018-05-21T20:00:34+02:00\",\"dateModified\":\"2018-05-23T15:00:51+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/05\\\/21\\\/c-fun-strange-facts\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/05\\\/21\\\/c-fun-strange-facts\\\/#webpage\"},\"articleSection\":\"C++, C++, fun, gotchas, standard\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/05\\\/21\\\/c-fun-strange-facts\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"position\":4,\"name\":\"C++\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/05\\\/21\\\/c-fun-strange-facts\\\/#listItem\",\"name\":\"C++ fun strange facts\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/05\\\/21\\\/c-fun-strange-facts\\\/#listItem\",\"position\":5,\"name\":\"C++ fun strange facts\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/05\\\/21\\\/c-fun-strange-facts\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/05\\\/21\\\/c-fun-strange-facts\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/05\\\/21\\\/c-fun-strange-facts\\\/\",\"name\":\"C++ fun strange facts\",\"description\":\"This article shows five random C++ constructs that you may find strange rather than intuitive.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/05\\\/21\\\/c-fun-strange-facts\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2018-05-21T20:00:34+02:00\",\"dateModified\":\"2018-05-23T15:00:51+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"C++ fun strange facts","description":"This article shows five random C++ constructs that you may find strange rather than intuitive.","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/","robots":"max-image-preview:large","keywords":"c++,gotchas,fun,standard","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/#article","name":"C++ fun strange facts","headline":"C++ fun strange facts","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"datePublished":"2018-05-21T20:00:34+02:00","dateModified":"2018-05-23T15:00:51+02:00","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/#webpage"},"articleSection":"C++, C++, fun, gotchas, standard"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","position":4,"name":"C++","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/#listItem","name":"C++ fun strange facts"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/#listItem","position":5,"name":"C++ fun strange facts","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/","name":"C++ fun strange facts","description":"This article shows five random C++ constructs that you may find strange rather than intuitive.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2018-05-21T20:00:34+02:00","dateModified":"2018-05-23T15:00:51+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"C++ fun strange facts","og:description":"This article shows five random C++ constructs that you may find strange rather than intuitive.","og:url":"https:\/\/mariusbancila.ro\/blog\/2018\/05\/21\/c-fun-strange-facts\/","article:published_time":"2018-05-21T18:00:34+00:00","article:modified_time":"2018-05-23T13:00:51+00:00","twitter:card":"summary","twitter:title":"C++ fun strange facts","twitter:description":"This article shows five random C++ constructs that you may find strange rather than intuitive."},"aioseo_meta_data":{"post_id":"2938","title":"C++ fun strange facts","description":"This article shows five random C++ constructs that you may find strange rather than intuitive.","keywords":[{"label":"c++","value":"c++"},{"label":"gotchas","value":"gotchas"},{"label":"fun","value":"fun"},{"label":"standard","value":"standard"}],"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:04:51","updated":"2025-12-12 07:49:13","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":2,"uagb_excerpt":"The title might be a little bit misleading because, on one hand, you might not find these things funny if you are stumbling upon them and not understanding what is going on, and, on the other hand, they are not really strange when you pay attention to what is going on. However, here is a&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">fun<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">gotchas<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">standard<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">fun<\/span>","<span class=\"advgb-post-tax-term\">gotchas<\/span>","<span class=\"advgb-post-tax-term\">standard<\/span>"]}},"comment_count":"2","relative_dates":{"created":"Posted 8 years ago","modified":"Updated 8 years ago"},"absolute_dates":{"created":"Posted on May 21, 2018","modified":"Updated on May 23, 2018"},"absolute_dates_time":{"created":"Posted on May 21, 2018 8:00 pm","modified":"Updated on May 23, 2018 3:00 pm"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-Lo","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/2938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=2938"}],"version-history":[{"count":14,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/2938\/revisions"}],"predecessor-version":[{"id":2962,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/2938\/revisions\/2962"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=2938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=2938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=2938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}