I am a little confused on function pointers. I am trying to pass a function to handle the movement of a paddle, the function either returning an array of floats for a user (key presses) or for ai. I'm sure the class is still pretty bad, but I'm just trying to get it running right now. I have gotten it all down to one error, and that's foo is not defined.
Any help, bee it with foo, or anything else that comes to your attention would be greatly appreciated.
Code:
class Paddle4f
{
public:
Paddle4f(float length, float width, float height);
void move();
void setMoveFunc(float* MoveFunc(void));
void reset(float z); // how far on z, differ from user and ai
// again, public so collision can access it
struct info{
float x, y, z;
float w, l, h;
float* velocity;
float speed[3];
int score; //keeps track of each paddles score
}stats;
private:
float* (*foo)(void);
};
Paddle4f::Paddle4f(float length, float width, float height)
{
stats.l = length;
stats.w = width;
stats.h = height;
}
void Paddle4f::reset(float z)
{
stats.x = 0.0f;
stats.y = 0.0f;
stats.z = z;
}
void setMoveFunc(float* (*moveFunc)(void))
{
*foo = &moveFunc;
}
void Paddle4f::move()
{
stats.velocity = foo();
}
Thank you for your time and effort,
Joe