Hey Everyone,
I recently ran into a problem when passing 3 arrays into a function that is supposed to move a spacestation sprite around a planet. Any help would be greatly appreciated.
//Main.cpp
//
for(int c = 0; c < 3; c++) {
stat.CheckDraw(c, global.ViewX, global.ViewY)
stat.Move(c, planet.PlanetSize, planet.GlobalPlanetX, planet.GlobalPlanetY);
}
1 2 3 4 5 6
Errors-
error: no matching function for call to 'Spacestation::Move(int&, std::vector<float>&, std::vector<float>&, std::vector<float>&)'
note: candidate is:
note: void Spacestation::Move(int, float*, float*, float*)
note: no known conversion for argument 2 from 'std::vector<float>' to 'float*'
Still fairly new to coding, and I'm not sure where to go from here.
Thanks!
PlanetSize, GlobalPlanetX, and GlobalPlanetY are all pointers to vector, so you have to access their elements with (*x)[n]. Be careful with that because the compiler will perfectly accept x[n] by itself, although it will do something entirely different from what you might otherwise expect.
You have defined planet.PlanetSize, planet.GlobalPlanetX, and planet.GlobalPlanetY as vector<float> not float* or float[], right?
You need to right your function declaration like this instead:
1 2 3 4
void Spacestation::Move(int c, vector<float> PlanetSize, vector<float> GlobalPlanetX, vector<float> GlobalPlanetY);
//or like this if you want it to run a bit faster (I avoid the details as you said you were new.)
void Spacestation::Move(int c, const vector<float> &PlanetSize, const vector<float> &GlobalPlanetX, const vector<float> &GlobalPlanetY);
Although a vector is like an array, they are not the same thing! (And there is no way to implicitly cast a vector<T> into a T[].)