Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>On the particular question, <code>long long</code> is implemented by the compiler in a compiler + platform specific way (usually more platform than compiler dependent).</p> <p>As to the original misconception, no, not all types are classes in C++. The languages tries to provide a uniform syntax in as much as possible for all types, trying to have all types behave similarly in as much as possible, and be used in a similar way. As a matter of fact, it is actually quite the other way around: C++ tries in as much as possible to have classes behave like primitive types (<em>value semantics</em>).</p> <p>The particular reason to be able to initialize an integer that way is actually quite related to classes, just in a different way. In a class constructor definition there are <em>initializer lists</em> that define how each one of the members is initialized <em>before</em> the constructor block is executed. The syntax for each initializer element in the list is basically (I would have to lookup the exact definition): <code>member_name( initializer )</code>, so for example you would get:</p> <pre><code>class my_int_vector { int * p; int size; public: my_int_vector() : p(0), size(0) {} //... } </code></pre> <p>Both pointers and integers are <em>fundamental</em> types, but they can be initialized in a way similar to that of classes. If that type of initialization was not allowed for fundamental types, and only the <code>type name = value;</code> syntax was allowed, the initializer list syntax would have to be extended, and you would not be able to seamlessly change those types at a later time (say, change the <code>int</code> to a <code>atomic_int</code>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload