What I want to do is something like this:
void dosth(bool& a) {
a[2] = false;
}
int main() {
bool a[10];
dosth(a);
return 0;
}
I want to call by reference, with an array as argument. How to realize this?
Thx
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.
Like this:
Or without the typedef:
Or more generally:
If you’re not in C++0x, you can implement a (simple)
static_assertlike this:Which allows you uncomment the
static_assertand get a compile-time error if the array size is too small.