On May 24, 8:14 pm, Vulcan <vulcan.ea...@gmail.comwrote:
<code>
class Base {
};
class Class1 : public Base{
public:
void Function1();
}
void Tracker(Base b, void (Base::*callback)());
int main(){
Class1 o1;
Tracker(&o1, &Class1::Function1);}
</code>
The above code doesn't work because Function1 is only declared in the
derived class. Is there a way around this? I want to be able to have a
member function of a derived class as callback.
I am looking for a way to provide a function Function1 with an object
Object1 and a member function of that object as a callback.
The full story:
I have several classes representing graphical objects like rectangle,
line, circle all derived from a common base say BObject. I need to be
able to modify any selected shape on the screen by dragging with the
mouse. I want to create one function called Tracker which will handle
mouse move events and update the shape on the screen by calling a
function on the object being modified.
Writing mouse tracking code per shape will take up too much repetitive
code. I felt it would be better for the tracker to have a callback
which it can call every time the mouse moves and then call ReDraw().