TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Obscure C++ Features

17 pointsby adgasfover 8 years ago

7 comments

Animatsover 8 years ago
Made even more obscure by using dark grey on black.<p>I didn&#x27;t know you could overload the comma operator that way. The comma operator was for use in C macros, for when multiple expressions were necessary. It should have been deprecated in C++.<p>The comma operator has different precedence inside and outside square brackets.<p><pre><code> tab(1,2) </code></pre> is a function call with two arguments.<p><pre><code> tab[1,2] </code></pre> is an invocation of the comma operator. You can&#x27;t overload &quot;operator[]&quot; with multiple arguments and simulate multidimensional arrays.
lordnachoover 8 years ago
Placement new isn&#x27;t obscure or strange, it&#x27;s in all those red books.<p>You may not use it, but you can appreciate it&#x27;s very useful if you want that fine grained control that you&#x27;re using c++ for in the first place.<p>Most of the other examples are just pure weirdness that you should never use. The kind you find in online employment exams.
hellofunkover 8 years ago
Meh. Some of these are no longer problematic in recent versions of the language. Braced initialization obviates the most vexing parse, for example.
评论 #13222923 未加载
clishemover 8 years ago
These are features covered in every C++ book and if you don&#x27;t know them you can hardly call yourself a C++ programmer.<p>Furthermore, the first &#x27;C++ feature&#x27; is not even a feature. It is merely the result of the preprocessor translating a[b] to *(a+b). C has it too.
评论 #13223659 未加载
CorvusCryptoover 8 years ago
Am I the only one that just cringed reading the keyword replacement section? To me the example given seemed absolutely crazy. Can anyone validate this usage of the &quot;feature&quot;? It just seems so off.
评论 #13223212 未加载
评论 #13223081 未加载
评论 #13223064 未加载
评论 #13223101 未加载
topkekzover 8 years ago
&gt;Accessing an element of an array via ptr[3] is actually just short for <i>(ptr + 3). This can be equivalently written as </i>(3 + ptr) and therefore as 3[ptr], which turns out to be completely valid code.<p>C++ standard defines the syntax of a postfix expression as this<p><pre><code> postfix-expression: primary-expression postfix-expression[expression] postfix-expression[braced-init-list] </code></pre> [expression]primary-expression is not valid
acadienover 8 years ago
Avoid using these whenever possible. Readability is more important than WoahNeat Factor.
评论 #13223015 未加载