问题
I'm in the process of learning c++. Now i understand that a derived class cannot access its base class private members, but why a templatized one can ?
for instance something like this works fine:
class base {
static int x;
};
template<typename T>
class derived: public base{
T t;
public:
void setx(int i) {x=i;}
int getx(){return x;}
};
I'm using gcc 5.4 on linux.
回答1:
This is a known bug of GCC, which seems to fail in performing access checking correctly in templates. See Bug 58740.
Unfortunately it's still not fixed.
BTW: Clang fails to compile, as expected.
来源:https://stackoverflow.com/questions/49676271/why-can-a-templatized-derived-class-access-its-base-private-members-on-gcc