为什么这是编译器错误? (克++)

时间:2011-04-27 23:40:47

标签: c++ g++ compiler-errors

所以我试图在我的实用程序类中使用泛型比较仿函数。

我尝试定义它并像这样调用它

template <class T>
bool AVL_tree<T>::avl_insert(AVL_Node<T> *& top, const AVL_Node<T> * insertNode, bool & taller) {
    std::binary_function<T,T,bool>::first_argument_type insertNodeValue;
    insertNodeValue  = insertNode->data;
    std::binary_function<T,T,bool>::second_argument_type topValue;
    topValue = insertNode->data;
    std::binary_function<T,T,bool>::result_type cmp_result;
    cmp_result = comparer(insertNodeValue,topValue);
    std::binary_function<T,T,bool>::result_type cmp_result2;
    cmp_result2 = comparer(topValue,insertNodeValue);
    //Function continues from here
}

预计会出现特定的编译器错误;在insertNodeValue之前

topValue和cmp_result;

重复此错误

我真的不明白为什么这是一个语法错误,我正在处理这个引用:  http://www.cplusplus.com/reference/std/functional/binary_function/

2 个答案:

答案 0 :(得分:2)

这是一个从属名称,因此需要typename关键字:

typename std::binary_function<T,T,bool>::first_argument_type insertNodeValue;

与其他人相似。请参阅the SO FAQ entry on dependent names

答案 1 :(得分:0)

鉴于这些是依赖类型,您的第一步应该是添加typename

typename std::binary_function<T,T,bool>::first_argument_type insertNodeValue;