为什么模板化派生类可以在gcc上访问其基本私有成员? [英] Why can a templatized derived class access its base private members on gcc?

查看:86
本文介绍了为什么模板化派生类可以在gcc上访问其基本私有成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习c ++.现在我知道派生类无法访问其基类的私有成员,但是为什么一个模板化的类可以呢?

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;}
};

我正在Linux上使用gcc 5.4.

I'm using gcc 5.4 on linux.

推荐答案

这是GCC的已知错误,似乎无法在模板中正确执行访问检查.参见错误58740 .

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.

顺便说一句: Clang 未能按预期编译.

BTW: Clang fails to compile, as expected.

这篇关于为什么模板化派生类可以在gcc上访问其基本私有成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆