data-type function(data-type arrayVar[][n])
and
data-type function(data-type arrayVar[n][n])
But both are references. Is there no other way than to use vectors? The 2D array that need to be copied is same-sized and full through the whole program, so I'd rather stick to classic arrays.
These really aren't references. They are arrays (pointers, technically) who are being inserted as parameters. Post some concrete code to clarify the trouble you're having.
You can't. Arrays cannot be passed by value in C++.
If you want to do this, you must encase the array in some other container (like a struct or a vector or something).
But that's a bad idea. There's no reason to create a copy of the array, as that's computationally expensive and a big waste.
Just pass the array by pointer/reference like you're doing and just don't have the function change it. To ensure the function doesn't change it, pass by const pointer/reference:
1 2
void test(constint some_array[4][4]) {
some_array[0][0] = 666; // now this gives you a compiler error
Thanks. I already thought about using a struct, but since I'm writing knight's tour (the chess problem), I'd like to keep it as simple and basic as possible.
The code is already finished actually, but the problem are dead ends when the program has to return (function recursion). Values get changed in all functions, while they should stay unique for each function. And I know it's a bit insane to copy 8x8 array up to 64-times, but it's the most simple way that I could think of.
The thing is that every square has a number that tells the program how many moves are possible from that square. So when the program has to return, all those numbers have to be reset to the state where another "tour" is possible.
What do you suggest? Would copying 1-dimensional 64-element vector (or string) be any less terrible? Is there actually any major difference between 1D and multi-D array (performance and allocation-wise)?