Considering this delegate class:
template <class DELEGATECLASS, class METHODPTRSPEC>
class CLDelegate
{
public:
CLDelegate();
CLDelegate( DELEGATECLASS* instancePtr, METHODPTRSPEC methodPtr );
CLDelegate( const CLDelegate& rhs );
DELEGATECLASS* pInstance_;
METHODPTRSPEC pMethod_;
};
//-----------------------------------------------------------------------------
//
template <class DELEGATECLASS, class METHODPTRSPEC>
CLDelegate<DELEGATECLASS, METHODPTRSPEC>::CLDelegate()
: pInstance_( nullptr )
, pMethod_( nullptr )
{}
//-----------------------------------------------------------------------------
//
template <class DELEGATECLASS, class METHODPTRSPEC>
CLDelegate<DELEGATECLASS, METHODPTRSPEC>::CLDelegate( DELEGATECLASS*
instancePtr, METHODPTRSPEC methodPtr )
: pInstance_( instancePtr )
, pMethod_( methodPtr )
{}
//-----------------------------------------------------------------------------
//
template <class DELEGATECLASS, class METHODPTRSPEC>
CLDelegate<DELEGATECLASS, METHODPTRSPEC>::CLDelegate( const CLDelegate& rhs )
: pInstance_( rhs.pInstance_ )
, pMethod_( rhs.pMethod_ )
{}
I would like to use this delegate within another class, but I would have to have template parameters for the whole class, which I do not want, like this:
template<class DELEGATECLASS, class METHODPTR>
class SomeClass
{
public:
IOVFUCam();
~IOVFUCam();
// Data Members
private:
...
const CLDelegate<DELEGATECLASS, METHODPTR>& del_;
};
Since I do not want to use template parameters on the whole class I wonder if it is possible to have a dummy delegate in my class and change its type (at compile time ?) :
struct EmptyType
{};
class SomeClass
{
public:
template<class DELEGATECLASS, class METHODPTR>
IOVFUCam( CLDelegate<DELEGATECLASS, METHODPTR> del )
: del_(del)
{};
~IOVFUCam();
// Data Members
private:
...
const CLDelegate<EmptyType, EmptyType>& del_;
};
FrameHandler handler;
CLDelegate<FrameHandler,
void(FrameHandler::*)( IOBuffer::Ptr )>
del( &handler, &FrameHandler::ProcessImage );
SomeClass obj( del );
I rapidly read something that Alexandrescu wrote about TypeTraits, and I wonder if this could be applied to my issue, or another technique ?
Thanks a lot !