About nested class

Keywords: c++ class nested declaration

Question: 

i don't know why it doesn't work.

template <typename E>
class SearchTree {
public:
    class Iterator {
             Iterator& operator++();
    };
};

template <typename E>
Iterator& SearchTree<E>::Iterator::operator++() {}

warning C4346 : 'iterator' Dependent name is not a type

error C2061 : Syntax error: identifier 'iterator'

Answers: 

You want to fully specify the return value:

template <typename E>
SearchTree<E>::Iterator& SearchTree<E>::Iterator::operator++() {}

It's a question about scope.

With

template <typename E>
Iterator& SearchTree<E>::Iterator::operator++() {}

when you use the symbol Iterator for the return type, that type isn't known in that scope. You have to specify its scope:

template <typename E>
typename SearchTree<E>::Iterator& SearchTree<E>::Iterator::operator++() {}

On a related note, and why I added the typename keyword for the return type, see Where and why do I have to put the “template” and “typename” keywords?

You can use trailing return type to fix this:

template <typename E>
auto SearchTree<E>::Iterator::operator++() -> Iterator& {}

In the trailing return type, types can be inside the scope of the class.