0

I am a little bit confused by the use of typename in the declaration of the operator ++ below:

template<class T>
typename DoublyLinkedList<T>::Iterator& 
DoublyLinkedList<T>::Iterator::operator++() 
{ 
    // ToDo
    
}

I know they are interchangeable but is it also possible to use both of them like this? or does this mean something different?

The definition in the header file is as follows: Iterator& operator++();

3
  • 1
    For this purpose typename may not be replaced by class. See linked duplicates. However the use of class in the template parameter may be replaced by typename. Apr 15, 2022 at 8:13
  • could you elaborate more on the use of typename in this case please? Apr 15, 2022 at 8:14
  • I have added back the original duplicate, which explains why typename before the return type is required in the first place. In short: DoublyLinkedList<T> depends on a template parameter and so the compiler can't know without the keyword whether or not DoublyLinkedList<T>::Iterator is going to be a type before instantiation of the template happens. typename disambiguates this. Apr 15, 2022 at 8:17

0