【发布时间】:2014-08-30 13:31:38
【问题描述】:
我试图使用 C++11 的“使用 =”语法来定义模板化比较函数。然后我定义了一个模板函数,并希望将其分配给“ComparisonFunction”类型的 compareFunc。
template<typename ValueType> using ComparisonFunction = bool (*)
(ValueType const & val1, ValueType const & val2);
template<typename ValueType>
bool equalFunction(ValueType const & val1, ValueType const & val2) {
return val1==val2;
}
template<typename ValueType>
ComparisonFunction<ValueType> comparisonFunc = equalFunction<ValueType>; //Error is here
int main()
{
}
前几行有效,但声明 equalFunc(甚至没有给它一个值)给出了错误
error: template declaration of 'bool (* equalFunc)(const ValueType&, const ValueType&)
我在此错误中发现的所有内容都与不存在“using =" 语法的 C++03 相关。
提前致谢
【问题讨论】:
-
您询问类型定义,但您遇到的问题是函数定义或函数指针定义,而不是类型定义。
标签: templates c++11 typedef using