How do I initialize a pointer to a literal array?
I want *grid to point to the new allocated int array {1, 2, 3}.
int *grid = new int[3];
*grid = {1, 2, 3};
thank you.
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.
You can’t initialize a dynamically allocated array that way. Neither you can assign to an array(dynamic or static) in that manner. That syntax is only valid when you initialize a static array, i.e.
What I mean is that even the following is illegal:
In your case you can do nothing but copy the velue of each element by hand
You might avoid an explicit loop by using stl algorithms but the idea is the same
Some of this may have become legal in C++0x, I am not sure.