Why can a templatized derived class access its base private members on gcc?

时光总嘲笑我的痴心妄想 提交于 2019-12-08 16:25:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!