1
我试图编译以下行的代码和它失败:模板参数推导C++
template <typename T>
struct InputBlockParameterType {
typedef T type;
};
template <typename T, template <typename> class BlockTypeTrait>
struct BlockParameterImpl {
typedef typename BlockTypeTrait<T>::type type;
};
template <typename T>
struct InputBlockParameter {
typedef typename BlockParameterImpl<T, InputBlockParameterType>::type type;
};
struct Functor {
template <typename T>
bool operator()(typename InputBlockParameter<T>::type p) {
return true;
}
};
int main() {
InputBlockParameter<double>::type arg = 0.0;
Functor f;
f(arg);
return 0;
}
该错误是(MSVC 2013):
1>main.cpp(31): error C2783: 'bool Functor::operator()(InputBlockParameter<T>::type)' : could not deduce template argument for 'T'
1> main.cpp(21) : see declaration of 'Functor::operator()'
如果我改变算符到
struct Functor {
template <typename T>
bool operator()(T p) {
return true;
}
};
所有事情都按预期编译。
为什么代码的第一个版本不能编译?它是否在标准中定义的某个地方?
'::'左侧的所有内容都是未推演的上下文。 – 2014-12-05 13:01:50