Unknown parameter in array

Hi,

I am using an array of type integer as an argument in a function,

e.g. void Function(iaaArray[][45]){}

What I would like to do is have something like...

void Function(iaaArray[][iInt]){}

where iInt is an integer determined by the user.

So I can allow for different sized arrays to be passed into the function.

Can someone help me with this.

Thanks Krahl
Take the array as a pointer and pass the size separately:

void func(int* array, unsigned int size)
thanks for the reply firedraco.

I have tried and it doesn't seem to accept it.

This is a simplified version of what I'm doing...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

void func(int* piaaArray, unsigned int uiSize, unsigned int uiLength){
    for (int j = 0; j < uiLength; j++){
        for (int i = 0; i < uiSize; i++){
            std::cout << *piaaArray[j][i];
        }
    }
}

int main(){

int* piaaArray[5][8];

func(piaaArray, 5, 8);

return 0;

}


and when I place as argument iaaArray[][] it seems to insist on the size of the multidimensional array. I could easily just define the array to be a ridiculous size like iaaArray[900][900] because I know it won't ever need to be bigger than that but I'd prefer not to do that.
Last edited on
I'm pretty sure my compiler allows what the OP is asking for. Is that non-standard?
If it doesn't work with arrays it should work with vectors.
well anyway, what I actually ended up doing is creating my own 2 dimensional array in a 1 dimensional array since it's basically the same as a 2 dimensional array, you just need to be more careful where the next row comes in.

I am still interested in a solution to this though.

So Browni3141, your compiler allows for my code snippet?

That is a good solution.
You could also generate all overload functions with every possible number in columns (templates)
1
2
template<unsigned int cols>
void foo(int array[][cols],unsigned int rows);
Hey thanks ne555 I forgot I could use template functions.
Topic archived. No new replies allowed.