Can someone please enlighten me on why this-> is required to access a parent class member variable in this scenario?
template <int S>
class A
{
protected:
int x[S];
};
template <int S>
class B : public A<S>
{
void Initialise()
{
this->x[0] = 0; // OK
x[0] = 0; // error: 'x' was not declared in this scope
}
};
Thanks in advance...
EDIT:
This compiles OK:
template <int S>
class A
{
protected:
int x[S];
};
class B : public A<5>
{
void Initialise()
{
this->x[0] = 0; // OK
x[0] = 0; // OK
}
};
` is nothing until `S` is known, so you must qualify the name to ensure it's a member of parent class.– Jack Jun 05 '19 at 22:11::x[0] = 0` does work!– davidbak Jun 05 '19 at 22:12