The name reference
is declared in the base class, and the base class is a dependent type (its type depends on V
). There are special rules that apply to this situation: when the compiler sees the name reference
, it does not search the dependent base class scope, and therefore, does not find the name. In order to force the compiler to search dependent base class scopes, you must qualify the name.
You might think that iterator::reference
would do the trick. Unfortunately, this doesn't work either. iterator
as a shorthand for std::iterator<std::random_access_tag, V>
is itself declared inside the base class as its "injected class name". So iterator
will not be found either unless it is qualified by something.
You can type it out the long way: typename std::iterator<std::random_access_tag, V>::reference a;
. A more readable way is:
using base = typename myiterator::iterator;
typename base::reference a;
You can use base::
to force lookup in the base class scope during the rest of the myiterator
class definition.
In C++20, typename
can be omitted from these contexts.