In C# I could do this:
char[] a = new char[] {'a', 'a', 'a'};
But can I do something like that in C++? I tried:
char *a = new char [] {'a', 'a', 'a'};
But it doesn’t compile.
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.
This is a bug in the C++ spec (which doesn’t let this simple construct to compile). You need to supply the size
See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1469 . Note that if you parenthesize the type name it is a type-id and not a new-type-id and hence syntactically allows you to omit the size expression. So you may be able to find an implementation that allows you to say
Althought it is clear that it wasn’t the explicit intent that this is possible (and some rules in the
newparagraphs can be interpreted to forbid it).