有人可以启发我为什么在这种情况下访问父类成员变量需要this->吗?
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
}
};
预先感谢...
编辑:
这样可以编译:
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
}
};