Reputation: 55
The following code fails to compile under g++, with the following error:
"no matching function for call to 'GetRecById(int&, NULL)'":
template < typename T >
struct DummyLookup
{
static bool DoLookup( T& rec, const char* id )
{
rec = 123;
return true;
}
};
template < typename T,
template <class> class LookupPolicy
>
static bool GetRecById( T& rec, const char* id )
{
return LookupPolicy<T>::DoLookup( rec, id );
}
static void testLookup( void )
{
int rec = 0;
const bool ret = GetRecById< int, DummyLookup<int> >( rec, NULL );
std::cout << "rec = " << rec << std::endl; // should be 123
}
int main()
{
testLookup();
return 0;
}
The intention is that GetRecById() supports instantiation with different record queriying policies e.g. for unit testing purposes.
What am I doing wrong here? FWIW, it does compile under Sun Studio 10.
Thanks in advance.
Upvotes: 1
Views: 104
Reputation: 55425
The second parameter to GetRecById
is a template, but you're trying to pass a type. You need:
GetRecById< int, DummyLookup >( rec, nullptr );
// ^ Note, no template argument here
Upvotes: 4