For some reason this is giving me more trouble than i thought…
int *myArray[3];
myArray = new int[mySize];
does not work…
I’ve used a typedef before in a similar manner and it worked perfectly, but this time i dont want to create the typedef
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.
One might be tempted to do this:
Because
vectoris so nice for dynamically sized arrays. Unfortunately, while that declaration works, the resultingvectoris unusable.This will be just as efficient, if you have
::std::array(a C++11 feature) and it will actually work:If you can do this, I would highly recommend it.
vectoris much nicer and safer to deal with than an array you have to allocate yourself withnew.Otherwise, try this:
And since you don’t want to use a typedef for some odd reason, you can unwrap it like so: