I have an int array myArray[x][y] and I wish to pass this to a function by reference, but it seems like it either needs constant bounds or some odd pointer workaround? How do I do this properly?
Share
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.
An array with automatic storage duration always requires compile-time constant bounds. The fact that you can do
int array[x];wherexis not a compile-time constant in GCC is merely a non-portable extension. Indeed, you cannot pass such a non-standard array by reference to a function.You could just pass the bounds along with the array, but you’re much better off using a standard container such as
std::vector.