Callback-Example/Ball.h
2017-05-23 16:40:02 -04:00

29 lines
545 B
C++

#ifndef BALL_H
#define BALL_H
#include "GraphicsObject.h"
//#include "PhysicsObject.h"
class Ball : public GraphicsObject
{
public:
Ball() : GraphicsObject(&Ball::SetX, this) // pointer to self (specific instance)
{
instance_num = ++instance_counter;
}
static void SetX(int &x, void *instance)
{
Ball *ball = static_cast<Ball*>(instance);
ball->x = ball->instance_num; // prove we're accessing the right one
return;
}
private:
static int instance_counter;
int instance_num;
};
int Ball::instance_counter = 0;
#endif