|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> Correct. I was also pointing out that they get initialized to the type's
> version of zero, whatever that might be. (I.e., pointers may not have
> all zero bits in them; they get initialized to null instead.) Rarely can
> you see this difference. :-)
Actually it's possible to invoke the "default initialization" for any
type at any point in C++. For example if you do this:
int i = int();
the 'i' variable will be default-initialized with the "zero" value for
the type in question (which, in this case, is the integer 0).
One might ask what's the point. It's actually useful when you don't
know what the type actually is. This happens eg. with templates. You
could have, for example, this:
template<typename Type>
void foo()
{
Type i = Type(); // Default-initialize i, even if it's a basic type
...
}
Although mostly it's useful in situations where you want to create a
default-initialized temporary, for example in code like this:
someVector.push_back(Type());
That will work even if 'Type' is an int, a double or a pointer.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |