Consider this code:
template <typename T>
struct X{
struct Y{
unsigned i;
};
template<typename E>
struct Z : public Y {
unsigned foo(){
return i;
}
};
};
we have a class template X with nested classes Y and Z. Z is again a template and inherits from Y. Thus, it also inherits the field i. However, this code does not compile. The compiles says, that it cannot resolve i in the foo() method of Z. Prefixing i explicitly with this-> solves the problem.
If I remove the outer type X, then the prefix is no longer required and the code compiles fine as it is.
Why is this explicit this-> prefix required here?