#ifndef GRAPHICSOBJECT_H #define GRAPHICSOBJECT_H class GraphicsObject { public: // 2nd arg: pointer to callback function that takes a reference to an int as an argument GraphicsObject(int set_x) { x = set_x; user_data = NULL; callback = NULL; // function pointer } GraphicsObject(void (*set_callback)(int&, void*), void *set_user_data) { x = 0; user_data = set_user_data; callback = set_callback; // function pointer } int X() { // If you are SUPPOSED to callback, ... if(callback) // ... do so to ask for the new X value callback(x, user_data); return x; // either this was just set by callback, or it was always set by constructor. } //private: int x; void *user_data; private: void (*callback)(int&, void*); }; #endif