V
Vladimir Jovic
Hello,
I am having a template classes like this :
template< typename R, typename A1 >
class FuncTypeGeneral
{
typedef R return_type;
typedef A1 arg1_type;
};
template < typename FuncType >
class PublisherAdapterHelper
{
public:
typedef typename FuncType::arg1_type arg1_type;
void ExecuteTheSlot( void **arguments )
{
const arg1_type &arg1 = GetArg1< arg1_type >( arguments[1]
}
private :
template< typename T >
arg1_type & GetArg1( void * arg ) const
{
return * reinterpret_cast< arg1_type* > ( arg );
}
arg1_type GetArg1( void * arg ) const
{
return * reinterpret_cast< arg1_type* > ( arg );
}
};
Now if I instantiate this template with a non-reference parameter, it
compiles fine. For example like this :
template class PublisherAdapterHelper< FuncTypeGeneral< void, int > >;
But as soon as I instantiate it with a reference, it breaks the
compilation, because it tries to convert the cast to arg1_type&* :
template class PublisherAdapterHelper< FuncTypeGeneral< void, int & > >;
So, why the templated method is better fit in this case? It shouldn't be
called, right? The normal function looks like a better fit.
I am having a template classes like this :
template< typename R, typename A1 >
class FuncTypeGeneral
{
typedef R return_type;
typedef A1 arg1_type;
};
template < typename FuncType >
class PublisherAdapterHelper
{
public:
typedef typename FuncType::arg1_type arg1_type;
void ExecuteTheSlot( void **arguments )
{
const arg1_type &arg1 = GetArg1< arg1_type >( arguments[1]
}
private :
template< typename T >
arg1_type & GetArg1( void * arg ) const
{
return * reinterpret_cast< arg1_type* > ( arg );
}
arg1_type GetArg1( void * arg ) const
{
return * reinterpret_cast< arg1_type* > ( arg );
}
};
Now if I instantiate this template with a non-reference parameter, it
compiles fine. For example like this :
template class PublisherAdapterHelper< FuncTypeGeneral< void, int > >;
But as soon as I instantiate it with a reference, it breaks the
compilation, because it tries to convert the cast to arg1_type&* :
template class PublisherAdapterHelper< FuncTypeGeneral< void, int & > >;
So, why the templated method is better fit in this case? It shouldn't be
called, right? The normal function looks like a better fit.