In the code below I would like array to be defined as an array of size x when the Class constructor is called. How can I do that?
class Class { public: int array[]; Class(int x) : ??? { } }
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 the size of an array with a non-const dimension that can’t be calculated at compile time (at least not in current C++ standard, AFAIK).
I recommend using
std::vector<int>instead of array. It provides array like syntax for most of the operations.