以下代码在g++下编译失败,报错如下:
“调用 '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;
}
目的是 GetRecById() 支持使用不同的记录查询策略进行实例化,例如用于单元测试目的。
我在这里做错了什么?FWIW,它确实在 Sun Studio 10 下编译。
提前致谢。