The x and y coordinates are passed to the function using an array. The first array element is the x-coordinate and the second array element is the y-coordinate.
@liuyang you are right that is it's declaration here is it's call from main():
int ref = daGrid.getHexFromXYPos(tools.mosPos);
@Peter87 absolutely correct
@helios I do know that it's impossible to pass an entire poly dimensional array to a function (granted this is based on what I learned with VS2010)
however for a mono dimensional array any of the three following ways should work:
as f(int *a), I understand by default arrays are passed by reference
as f(int a[x]) explicitly telling a function expect an array of size x
int getHexFromXYPos(int[2]); I'm fairly sure I did...
as f(int a[]) explicitly telling a function to expect an array of unknown size.
Please let me know if I'm wrong, wont learn otherwise
The work around isn't difficult so I'm not heartbroken if that has to be the case (I verify what helios says in that only the first element is getting passed)
if it helps here is the function in question
int::Grid::getHexFromXYPos(int mosPos[2])
{
for (int i = 0; i < hexGrid.size(); i++)
{
if (hexGrid.at(i)->xPos >= mosPos[0] + 40 && hexGrid.at(i)->xPos <= mosPos[0] + 40
&& hexGrid.at(i)->yPos <= mosPos[1] + 60 && hexGrid.at(i)->xPos >= mosPos[1] + 60)
{
return hexGrid.at(i)->vectPos;
}
}
return -1; // on the event no such hex exists... this should never happen
}
and I forgot to say thank you for your time in my original post, so thank you!
The compiler treats a as a pointer and doesn't care about the size x. When you pass an array to this function what is actually being passed is a pointer to the first element in the array.