bon ben en fait ca marche
allez juste parceque j'ai envie de te rayer les yeux, jle poste
pour pouvoir ecrire ca:
class A
{
public:
A();
int Truc() const;
int Truc(int x = 0) const;
};
void Tralala()
{
A a;
(a.*GetNaked(&A::Truc))(); // appelle a.Truc()
(a.*GetDefault(&A::Truc))(69); // appelle a.Truc(int x) avec x = 69
CallNaked(a, &A::Truc)(); // appelle a.Truc()
CallDefault(a, &A::Truc)(69); // appelle a.Truc(int x) avec x = 69
}
#triutile#
faut ca:
template<typename _Type, typename _Ret, typename _T0, typename _T1>
struct TMethodPointerWrapper
{
typedef _Ret (_Type::*Signature)(_T0, _T1);
_Type *m_Object;
Signature m_Method;
TMethodPointerWrapper(_Type &object, Signature method) : m_Object(&object), m_Method(method) {}
_Ret operator () (_T0 a0, _T1 a1) { return (m_Object->*m_Method)(a0, a1); }
};
template<typename _Type, typename _Ret, typename _T0>
struct TMethodPointerWrapper<_Type, _Ret, _T0, void>
{
typedef _Ret (_Type::*Signature)(_T0);
_Type *m_Object;
Signature m_Method;
TMethodPointerWrapper(_Type &object, Signature method) : m_Object(&object), m_Method(method) {}
_Ret operator () (_T0 a0) { return (m_Object->*m_Method)(a0); }
};
template<typename _Type, typename _Ret>
struct TMethodPointerWrapper<_Type, _Ret, void, void>
{
typedef _Ret (_Type::*Signature)();
_Type *m_Object;
Signature m_Method;
TMethodPointerWrapper(_Type &object, Signature method) : m_Object(&object), m_Method(method) {}
_Ret operator () () { return (m_Object->*m_Method)(); }
};
//----------------------------------------------------------------------------
template<typename _Type, typename _Ret, typename _T0, typename _T1>
struct TMethodPointerWrapperConst
{
typedef _Ret (_Type::*Signature)(_T0, _T1) const;
const _Type *m_Object;
Signature m_Method;
TMethodPointerWrapperConst(const _Type &object, Signature method) : m_Object(&object), m_Method(method) {}
_Ret operator () (_T0 a0, _T1 a1) { return (m_Object->*m_Method)(a0, a1); }
};
template<typename _Type, typename _Ret, typename _T0>
struct TMethodPointerWrapperConst<_Type, _Ret, _T0, void>
{
typedef _Ret (_Type::*Signature)(_T0) const;
const _Type *m_Object;
Signature m_Method;
TMethodPointerWrapperConst(const _Type &object, Signature method) : m_Object(&object), m_Method(method) {}
_Ret operator () (_T0 a0) { return (m_Object->*m_Method)(a0); }
};
template<typename _Type, typename _Ret>
struct TMethodPointerWrapperConst<_Type, _Ret, void, void>
{
typedef _Ret (_Type::*Signature)() const;
const _Type *m_Object;
Signature m_Method;
TMethodPointerWrapperConst(const _Type &object, Signature method) : m_Object(&object), m_Method(method) {}
_Ret operator () () { return (m_Object->*m_Method)(); }
};
//----------------------------------------------------------------------------
template<typename _Type, typename _Ret>
typename TMethodPointerWrapper<_Type, _Ret, void, void>::Signature GetNaked(_Ret (_Type::*p)())
{
return p;
}
template<typename _Type, typename _Ret, typename _T0>
typename TMethodPointerWrapper<_Type, _Ret, _T0, void>::Signature GetDefault(_Ret (_Type::*p)(_T0))
{
return p;
}
template<typename _Type, typename _Ret, typename _T0, typename _T1>
typename TMethodPointerWrapper<_Type, _Ret, _T0, _T1>::Signature GetDefault(_Ret (_Type::*p)(_T0, _T1))
{
return p;
}
template<typename _Type, typename _Ret>
typename TMethodPointerWrapperConst<_Type, _Ret, void, void>::Signature GetNaked(_Ret (_Type::*p)() const)
{
return p;
}
template<typename _Type, typename _Ret, typename _T0>
typename TMethodPointerWrapperConst<_Type, _Ret, _T0, void>::Signature GetDefault(_Ret (_Type::*p)(_T0) const)
{
return p;
}
template<typename _Type, typename _Ret, typename _T0, typename _T1>
typename TMethodPointerWrapperConst<_Type, _Ret, _T0, _T1>::Signature GetDefault(_Ret (_Type::*p)(_T0, _T1) const)
{
return p;
}
//----------------------------------------------------------------------------
template<typename _Type, typename _Ret>
TMethodPointerWrapper<_Type, _Ret, void, void> CallNaked(_Type &object, _Ret (_Type::*p)())
{
return TMethodPointerWrapper<_Type, _Ret, void, void>(object, p);
}
template<typename _Type, typename _Ret, typename _T0>
TMethodPointerWrapper<_Type, _Ret, _T0, void> CallDefault(_Type &object, _Ret (_Type::*p)(_T0))
{
return TMethodPointerWrapper<_Type, _Ret, _T0, void>(object, p);
}
template<typename _Type, typename _Ret, typename _T0, typename _T1>
TMethodPointerWrapper<_Type, _Ret, _T0, _T1> CallDefault(_Type &object, _Ret (_Type::*p)(_T0, _T1))
{
return TMethodPointerWrapper<_Type, _Ret, _T0, _T1>(object, p);
}
template<typename _Type, typename _Ret>
TMethodPointerWrapperConst<_Type, _Ret, void, void> CallNaked(_Type &object, _Ret (_Type::*p)() const)
{
return TMethodPointerWrapperConst<_Type, _Ret, void, void>(object, p);
}
template<typename _Type, typename _Ret, typename _T0>
TMethodPointerWrapperConst<_Type, _Ret, _T0, void> CallDefault(_Type &object, _Ret (_Type::*p)(_T0) const)
{
return TMethodPointerWrapperConst<_Type, _Ret, _T0, void>(object, p);
}
template<typename _Type, typename _Ret, typename _T0, typename _T1>
TMethodPointerWrapperConst<_Type, _Ret, _T0, _T1> CallDefault(_Type &object, _Ret (_Type::*p)(_T0, _T1) const)
{
return TMethodPointerWrapperConst<_Type, _Ret, _T0, _T1>(object, p);
}
#tripropre#
(c'est pour des methodes jusqu'a deux parametres par defaut, pour plus de parametres, faut copier/coller et les rajouter dans les specialisations

mais ya surement moyen de rendre ca beaucoup plus compact avec C++11)
par contre, le rendre plus utile, c'est pas dit
