繁体   English   中英

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

[英]Why is this a compiler error? (g++)

所以我试图在我的实用程序 class 中使用通用比较函子。

我试图定义它并这样称呼它

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
}

预计会出现特定的编译器错误; 在插入节点值之前

topValue 和 cmp_result 重复此错误;

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

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

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

对其他人也是如此。 请参阅有关依赖名称的 SO FAQ 条目

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM