Search
 
SCRIPT & CODE EXAMPLE
 

CPP

error: use of parameter outside function body before ] token c++

If you are using GCC, then you are to pass the length of the array 
as a parameter to the function.

void foo (int m, int arr[][m]) {
    //...
}

However, there seems to be a bug in either the compiler or 
the documentation, as the above function prototype syntax 
only works when compiling C code, not C++ (as of gcc version 4.8.2). 
The only work-around I found was to use a void * parameter, 
and cast it int the function body:

int foo_workaround (int m, void *x)
{
    int (*arr)[m] = static_cast<int (*)[m]>(x);
    //...
}

There are other solutions if you do not want to rely on a compiler
extension. If you don't mind a separate allocation for each row, 
you can use a vector of vectors, for example:

std::vector<std::vector<int> > arr(n, std::vector<int>(m));
Comment

PREVIOUS NEXT
Code Example
Cpp :: taking integer input from file in c++ 
Cpp :: C++ Volume of a Cube 
Cpp :: varint index 
Cpp :: CPP print executable name 
Cpp :: arduino bleutooth module hc-05 with led 
Cpp :: c++ solver online free 
Cpp :: c++ online 
Cpp :: how does sorting array works in c++ 
Cpp :: Corong_ExerciseNo3 
Cpp :: Variabili globali c++ 
Cpp :: initalising array c++ 
Cpp :: vector and algorithm 
Cpp :: selection sort algorithm in cpp 
Cpp :: Calculating Function codeforces in c++ 
Cpp :: transpose function example in c++ 
Cpp :: C++ Join thread 
Cpp :: and condtion c++ 
Cpp :: comentar todas linhas de uma vez vs code 
Cpp :: contains in c++ map 
Cpp :: Edmonds-Karp algorithm C++ 
Cpp :: hamming c++ 
Cpp :: c++ insertion in astack 
Cpp :: flutter container margin 
Cpp :: c++ Unable to get CMake Tutorial example to compile 
Cpp :: armstrong number 
Cpp :: how to user input in string to open files in c++ 
Cpp :: sro in c++ 
Cpp :: deal with bad input cpp 
Cpp :: ‘npos’ is not a member of ‘std’ 
Cpp :: cast unreal c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =