What I'm trying to do:
User inputs two numbers.
Array is declared using those numbers as dimensions.
Function outside main() is filling the array.
Array is accessed in main() for further thingies.
What I have problem with:
Function + array combination doesn't seem to work as I think.
What I did:
void tablica1(int h, int w)
{
int m,n;
for(m=0; m<h; m++)
for(n=0; n<w; n++)
{
arr[h][w]=1;
}
}
What happens:
array arr is inaccessible in tablica1() because it has not been declared in that function.
Of course, when I declare the array in tablica1() it becomes inaccessible in main().
Possible solutions:
- Passing arr to
tablica1()as a reference - no idea how to do that - Declaring arr in
tablica1()and somehow passing it tomain()- no idea how to do that
Other possible solutions?
std::vector<std::vector<int>>as one possible solution.std::array<>will dynamically size... how? In the question: "Array is declared using those numbers as dimensions"arrin themainfunction. Please post that declaration (even though it doesn't work). This will clarify your question and help you get better answers. Please also specify your compiler (gcc/other); this may be important.