2011-04-27 216 views
0

所以我试图在我的工具类中使用泛型比较函子。这是一个编译器错误? (g ++)

我试图去定义它,并调用它像这样

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/

+3

为什么这一切:'的std :: binary_function :: first_argument_type'?而不是只是'T'? – 2011-04-27 23:46:19

回答

2

这是一个从属名称,所以它需要typename关键字:

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

对其他人也一样。见the SO FAQ entry on dependent names

0

鉴于这些依赖类型,第一步可能应该添加typename

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