Boost.Function is very nice and definitely the way to go if available.
For what it's worth, here's what I do in my environment - which doesn't have boost and must compile under VC 6.
I use polymorphic hierarchy for my callback objects. This allows me to have a base-callback object that doesn't have a templated type applied to it. The downside is that the callback signature is tightly coupled to all objects. Here's an example:
Code:
#include <iostream>
using namespace std;
//------------------------------------------------------------------------------
struct BaseCallback
{
virtual void Invoke(int, int) = 0;
};//BaseCallback
// Functor object for non-member functions
template <typename Functor_t>
struct NonMemCallback : public BaseCallback
{
Functor_t m_cb;
explicit NonMemCallback(const Functor_t &cb) : m_cb(cb) {}
virtual void Invoke(int a, int b)
{
m_cb(a, b);
}//Invoke
};//NonMemCallback
// Functor object for member functions
template <typename Obj_t>
struct MemCallback : public BaseCallback
{
typedef void (Obj_t::*MemberFunc_t)(int, int);
MemberFunc_t m_cb;
Obj_t *m_obj;
MemCallback(Obj_t *obj, MemberFunc_t cb) : m_cb(cb), m_obj(obj) {}
virtual void Invoke(int a, int b)
{
(m_obj->*m_cb)(a, b);
}//Invoke
};//MemFunctor
// Helper for NonMemCallback<>
template<typename Functor_t>
BaseCallback* CreateCallback(const Functor_t &func)
{
return new NonMemCallback<Functor_t>(func);
}//CreateCallback
// Helper for MemCallback<>
template <typename Obj_t>
BaseCallback* CreateCallback(Obj_t *obj, void (Obj_t::*fun)(int, int))
{
return new MemCallback<Obj_t>(obj, fun);
}//CreateCallback
//------------------------------------------------------------------------------
void foo(int a, int b)
{
cout << "::foo(" << a << ',' << b << ')' << endl;
}//foo
struct foo_functor
{
void operator()(int a, int b)
{
cout << "foo_functor(" << a << ',' << b << ')' << endl;
}//operator()
};//foo_function
struct A
{
void foo(int a, int b)
{
cout << "A::foo(" << a << ',' << b << ')' << endl;
}//foo
};//A
//------------------------------------------------------------------------------
int main()
{
A a;
BaseCallback *cb1 = CreateCallback(&foo);
BaseCallback *cb2 = CreateCallback(foo_functor());
BaseCallback *cb3 = CreateCallback(&a, &A::foo);
cb1->Invoke(1, 1);
cb2->Invoke(2, 2);
cb3->Invoke(3, 3);
delete cb1;
delete cb2;
delete cb3;
return 0;
}//main
So whether you use boost::function or BaseCallback, you can remove the template<> off of Synchronize() and the pClass parameter (assuming you only needed pClass for callback purposes).
gg