donkon donkon - 2 months ago 9
C++ Question

Variable in Function Signature Out of Scope C++

I am just starting out in C++, so excuse the ignorance.

I have written the following code, but cannot compile.

void dosome(const bool[][2] arr, const int juice) {
for (int i = 0; i < juice; i++) {
anotherfunc(arr[i], juice, 2);
}
}


These are the compile errors I receive, but don't know how to interpret them.

function_args.c++:8:29: error: expected ',' or '...' before 'arr'
void dosome(const bool[][2] arr, const int juice) {
^
function_args.c++: In function 'void dosome(const bool (*)[2])':
function_args.c++:9:25: error: 'juice' was not declared in this scope
for (int i = 0; i < juice; i++) {
^
function_args.c++:10:21: error: 'arr' was not declared in this scope
anotherfunc(arr[i], juice, 2);
^
function_args.c++:10:37: error: 'anotherfunc' was not declared in this scope
anotherfunc(arr[i], juice, 2);


arr
and
juice
were not declared in this scope

any explanations?

Answer
void dosome(const bool arr[][2], const int juice) {
//                        ^^^^^ 
    for (int i = 0; i < juice; i++) {
        anotherfunc(arr[i], juice, 2);
    }
}