C ++编译器错误涉及私人继承 [英] C++ compiler error involving private inheritance

查看:178
本文介绍了C ++编译器错误涉及私人继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释以下编译器错误:

Could someone please explain the following compiler error to me:

struct B
{
};

template <typename T>
struct A : private T
{
};

struct C : public A<B>            
{                                                                             
    C(A<B>);   // ERROR HERE
};

指示行处的错误是:

test.cpp:2:1: error: 'struct B B::B' is inaccessible
test.cpp:12:7: error: within this context

推荐答案

解决方案

尝试 A< :: B> A< struct B>

c $ c> C ,对$ B 的非限定引用将选择所谓的 inject-class-name 它通过基类 A 引入。由于 A B 私下继承,因此 injected-class-name 也是私人的,因此无法访问 C

Inside of C, unqualified references to B will pick up the so-called injected-class-name, it is brought in through the base class A. Since A inherits privately from B, the injected-class-name follows suit and will also be private, hence be inaccessible to C.

另一天,另一种语言quirk ...

Another day, another language quirk...

这篇关于C ++编译器错误涉及私人继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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