Home:ALL Converter>C++ compiler error involving private inheritance

C++ compiler error involving private inheritance

Ask Time:2012-02-10T13:28:00         Author:HighCommander4

Json Formatter

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

The error at the indicated line is:

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

What exactly is inaccessible, and why?

Author:HighCommander4,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/9223153/c-compiler-error-involving-private-inheritance
Xeo :

Try A< ::B> or A<struct B>.\n\nInside 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.\n\nAnother day, another language quirk...",
2012-02-10T05:35:14
Dmitriy Kachko :

The problem is name shielding of struct B .\nCheck it out:\n\nstruct B{};\n\nstruct X{};\n\ntemplate <class T>\nstruct A : private T\n{};\n\nstruct C : public A<B>\n{\n C(){\n A<X> t1; // WORKS\n // A<B> t2; // WRONG\n A< ::B> t3; // WORKS\n } \n};\n\nint main () {\n}\n",
2012-02-10T05:44:26
yy