This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
Example code: class A { }; class B : A { }; class C : B { public: int c(A *a) { return 7; } }; int main() { A a; C c; return c.c( &a ); } Gives the error message: g++ main.cc main.cpp:1: `class A' is inaccessible main.cpp:9: within this context Which is true, but not relevant. C never tries to access A through B.
No gcc is correct because the type A is interjected into B. and is private as the base class is private.
Could someone take another look at this? I don't mean to waste your time, but I don't understand the explanation given. I know of another compiler that handles the example code without any problems. I agree that 'A is inaccessible' from C, but the code doesn't try to access it. Consider this one word change to class C: class C : B { public: int c(void *a) { return 7; } }; Now it compiles fine. Before this is closed again I'd like to understand why it should matter what type an unreferenced parameter is. Why shouldn't I be able to pass a pointer to an object of type A (completely unrelated to C) to one of C's methods? Thanks in advance.
Huh? unused paramaters are still need to be able to compile and be accessible. If that compiler handles this code, well that compiler has a bug in it. ICC gives the following warning though (but note it says allowed for compatiblity): t.cc(9): warning #525: type "A::A" is an inaccessible type (allowed for compatibility) The point is A is inaccessible in the class C because it is interjected into B. If you want to use the global class A, use ::A and that works.
Subject: Re: g++ rejects valid code with 'is inaccessible' error On Thu, Mar 10, 2005 at 02:25:03AM -0000, matthew dot whitney at gmail dot com wrote: > Now it compiles fine. Before this is closed again I'd like to understand why it > should matter what type an unreferenced parameter is. Why shouldn't I be able to > pass a pointer to an object of type A (completely unrelated to C) to one of C's > methods? Thanks in advance. You could if A were completely unrelated to C. You have C deriving from B, and B deriving from A, which means that the name A binds to the base class inside C; and the base class is inaccessible, so it may not be referred to. As Andrew said, use ::A. If you want chapter and verse from the C++ standard, I can't help you, but I'm sure someone else here can.
Just ask on comp.lang.c++.moderated for more information. We help with C++ issues a little, but we cannot explaint things in detail to every C++ developer in the world. Ah, and when Andrew said "interjected" he really meant "injected" :)
Thanks for the explanation - I understand what's happening now. Next time I'll take it to comp.lang.c++.moderated before bothering you guys. Anyway sorry to have wasted your time.