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
有帮助吗?

解决方案

You need:

typename List<T>::iterator

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top