When we write int a;
, it doesn't mean that we are creating an object of class int.
When we write
int a;
, it doesn't mean that we are creating an object of class int.
int a;
does indeed create an object in C++. It's an object of type int
with indeterminate value if it has automatic storage duration; or with value 0
, if it has static storage duration. But there is no "class int
" because int
is not a class type.
int
is a:
Seems like you got a bit confused in your previous question :)
In int x = 12;
, you are creating an object of type int
that is named x
and has value 12.
The idea of object in C++ is not the same as in most other languages, and most certainly is not the same as is commonly used in object-oriented programming circles. An object in C++ is a region of storage.
If something has a type, it's either an object, a reference, or a function.
Which header file shows what it is?
The language simply requires that the type int
has to exist and have certain characteristics (like being integral and having a sign). All compilers I know of simply treat all the builtin types specially and that's why you won't find a definition for them in the standard library headers. In fact, they can't provide a definition for them in any header using C++, because the language doesn't provide any means of defining fundamental types. They could only either:
The builtin types are effectively magic.