簡體   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