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