class A {};
class B : private A {
};
class C : public B {
public:
void f() {
A a; // This line causes error, but works when it is in main() function
}
};
int main()
{
C c;
// A a; --> This line works
return 0;
}
I am guessing this has something to do with B inheriting privately from A but cannot put my finger on it.
EDIT: Error is “class A is not visible”. Compiled with g++.
name lookup is separate from access checking. and when you inherit from a class, that class’ name is injected into the inheriting class’ scope. so in class
Cyou pick up the nameAbut it’s not accessible.one solution is to write
::A a;instead ofA a;.