Does C++ do value initialization on simple POD typedefs?
Assuming
typedef T* Ptr;
does
Ptr()
do value-initialization and guarantee to equal (T*)0?
e.g.
Ptr p = Ptr();
return Ptr();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It does. For a type
T,T()value-initializes an “object” of typeTand yields an rvalue expression.Same for pod-classes:
Also true for some non-POD classes that have no user declared constructor:
Since you cannot do
A a()(creates a function declaration instead), boost has a classvalue_initialized, allowing to work around that, and C++1x will have the following, alternative, syntaxIn the dry words of the Standard, this sounds like
Since a typedef-name is a type-name, which is a simple-type-specifier itself, this works just fine.