0

So I'm attempting to utilize a generic compare functor in my utility class.

I attempt to define it and call it like so

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
}

The specific compiler error is expected ; before insertNodeValue

This error is repeated for topValue and cmp_result;

I don't really understand why this is a syntax error, I'm working off this reference: http://www.cplusplus.com/reference/std/functional/binary_function/

Peter Smith
  • 849
  • 2
  • 11
  • 28

2 Answers2

2

It's a dependent name, so it requires the typename keyword:

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

Similarly for others. See the SO FAQ entry on dependent names.

Community
  • 1
  • 1
Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224
0

Given that these are dependent types, your first step should probably be to add typename:

typename std::binary_function<T,T,bool>::first_argument_type insertNodeValue;
Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111