Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

template matching problem

32 views
Skip to first unread message

Norman J. Goldstein

unread,
Mar 10, 2015, 9:35:09 PM3/10/15
to
Below, is code that has 4 different conditional compilation blocks.
When the first block is chosen, the compilation breaks with the msg:

error: template-id ‘copy<>’ for
‘bool copy(WD&, WD::IoRefrType<A>)’
does not match any template declaration
template bool copy( WD&,

which refers to the inability of the compiler to explicitly instantiate,
as requested at the bottom of the source code.

However, when any of the last 3 blocks is chosen, instead,
the compilation is fine. I am using gcc 4.8.3 on linux x86-64.

Explanations or suggestions much appreciated!

/////////////////////// source code ///////////////
struct WD
{
template< typename T >
using IoRefrType = const T&;
};

class A;

#if 1 // Two template parameters: Error
template< typename S, typename T >
bool copy( S& s,
typename S:: template IoRefrType< T > t )
{ return true; }
#elif 1 // Only the first template parameter: OK
template< typename S >
bool copy( S& s,
typename S:: template IoRefrType<A> )
{ return true; }
#elif 1 // Only the second template parameter: OK
template< typename T >
bool copy( WD& ,
typename WD:: template IoRefrType< T > t )
{ return true; }
#else // Simpler two template parameters: OK
template< typename S, typename T >
bool copy( S& s,
const T& t )
{ return true; }
#endif

template bool
copy( WD&,
typename WD:: template IoRefrType<A> );
/////////////////////////////////////////////////////

fefe

unread,
Mar 11, 2015, 2:55:48 AM3/11/15
to
In this template,
> template< typename S, typename T >
> bool copy( S& s,
> typename S:: template IoRefrType< T > t )
> { return true; }
in the type `typename S:: template IoRefrType<T>`, the template parameter `S` is in a non-deduced context, thus rendering the whole `typename S:: template IoRefrType<T>` non-deduced. This means, the type `T` cannot be automatic deduced.

You may try give the template arguments explicitly:

template bool
copy<WD, A>( WD&,

Norman J. Goldstein

unread,
Mar 11, 2015, 11:56:47 AM3/11/15
to
This works! Thanks very much, and for the explanation.
0 new messages