I declare and fill a 2d char array in array.cpp and want to pass it to the rest of my program. From what I've read so far there are various ways to do that but I want the following approach: array.cpp should be completely independent from the rest of the program, the only link between these parts should be a function that returns either my 2d array or a pointer to it.
This is my array.cpp at the moment:
1 2 3 4 5 6 7 8
// some global variables.
my_array [10][10000]; // declaring my array.
void init_array ()
{
// fills array with data.
}
I want init_array to either return my_array or pointer to it. What also confuses me is even if I manage to pass my_array as return value, how am I going to copy it? Something like this shouldn't work as far as I'm awaare: my_array2 = my_array, so how is it done then?
Also, I guess returning a pointer should be a better idea, since if I return an array there basicly would be 2 arrays in memory, original one and a copy of it, right?
Don't use C-style plain arrays in this case, they will cause you a lot of problems. Use a real object like std::vector so that you don't have to deal with the weird properties of plain arrays.