0

I'm having some trouble doing a comparison function in a doubly linked list that's purpose is to "check if two lists contain the same sequence of elements. Two lists are equal if they have the same number of elements and the elements at the corresponding position are equal" It seems right but I'm getting errors when I try to compile it. Here's the code, used along with a separate header file that's description is:

A header file List.h is provided, which contains the interfaces of the doubly-linked list class template List.

Here's my comparison function:

template <typename T>
bool operator==(const List<T> & lhs, const List<T> & rhs){
    if (lhs.theSize == rhs.theSize){
/*line345*/ for(List<T>::iterator itr = lhs.begin(), List<T>::iterator itr_2 = rhs.begin(); itr != lhs.end(); ++itr, ++itr_2){

            if(*itr != *itr_2)
            return false;
        }
        return true;
    }
    else
    return false;
}

Let me know if I need to provide more code. My errors are:

List.cpp:345:35: error: expected ';' before 'itr'
List.cpp:345:93: error: 'itr' was not declared in this scope
List.cpp:345:120: error: 'itr_2' was not declared in this scope
List.cpp:344:9: error: within this context
List.cpp:345:91: error: dependent-name 'cop4530::List<T>::iterator' is parsed as a non-type, but instantiation yields a type
t0mppa
  • 3,983
  • 5
  • 37
  • 48
Tommy Boi
  • 37
  • 1
  • 7
  • possible duplicate of [Where and why do I have to put the "template" and "typename" keywords?](http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – erenon Feb 21 '14 at 22:17

1 Answers1

0

You need:

typename List<T>::iterator

Because iterator is a dependant name. (The kind of the name depends on a template argument)

erenon
  • 18,838
  • 2
  • 61
  • 93
  • I think that solved part of the problem. But i'm still getting other errors: List.cpp:344:9: error: within this context List.cpp:345:60: error: conversion from âcop4530::List >::const_iteratorâ to non-scalar type âcop4530::List >::iteratorâ requested List.cpp:345:108: error: conversion from âcop4530::List >::const_iteratorâ to non-scalar type âcop4530::List >::iteratorâ requested List.cpp:345:108: error: could not convert âitr_2â from âcop4530::List >::iteratorâ to âboolâ – Tommy Boi Feb 22 '14 at 00:00