Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > 'B' is an inaccessible base of 'D'

Reply
Thread Tools

'B' is an inaccessible base of 'D'

 
 
yuvalif@gmail.com
Guest
Posts: n/a
 
      12-26-2005
Hi All,
I fail to compile the following code (well, not exactly that code...):

class BB
{
};

class B
{
public:
static B* Create(int i);
};

class D0 : public BB, B
{
};

class D1 : public BB, B
{
};


B* B::Create(int i)
{
if (i == 0)
return new D0();
else
return new D1();
}

int main()
{
B *b = B::Create(1);
delete b;
return 0;
}

And get: "error: 'B' is an inaccessible base of 'D0', 'B'
is an inaccessible base of 'D1' "
But when I change the order of inheritance: "class D0 : public B, BB",
everything works fine.
Why?

TID, Yuval.

 
Reply With Quote
 
 
 
 
John Carson
Guest
Posts: n/a
 
      12-26-2005
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com
> Hi All,
> I fail to compile the following code (well, not exactly that code...):
>
> class BB
> {
> };
>
> class B
> {
> public:
> static B* Create(int i);
> };
>
> class D0 : public BB, B
> {
> };
>
> class D1 : public BB, B
> {
> };
>
>
> B* B::Create(int i)
> {
> if (i == 0)
> return new D0();
> else
> return new D1();
> }
>
> int main()
> {
> B *b = B::Create(1);
> delete b;
> return 0;
> }
>
> And get: "error: 'B' is an inaccessible base of 'D0', 'B'
> is an inaccessible base of 'D1' "
> But when I change the order of inheritance: "class D0 : public B, BB",
> everything works fine.
> Why?
>
> TID, Yuval.


You are apparently assuming that access qualifiers like

public BB, B

work in the same way as variable declarations, e.g.,

int x, y

i.e., that they continue in effect for identifiers after the first. They
don't. The access qualifier only has effect on the class that immediately
follows. If you omit a declaration, then you get the default access, which
is private in this case. Do it this way:

class D0 : public BB, public B
{
};

class D1 : public BB, public B
{
};


--
John Carson


 
Reply With Quote
 
 
 
 
Zara
Guest
Posts: n/a
 
      12-26-2005
On 25 Dec 2005 22:16:51 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

>Hi All,
>I fail to compile the following code (well, not exactly that code...):
>
>class BB
>{
>};
>
>class B
>{
>public:
> static B* Create(int i);
>};
>
>class D0 : public BB, B


This is equivalent to class D0: public BB, private B
>{
>};
>
>class D1 : public BB, B
>{
>};
>
>
>B* B::Create(int i)
>{
> if (i == 0)
> return new D0();
> else
> return new D1();
>}
>
>int main()
>{
> B *b = B::Create(1);
> delete b;
> return 0;
>}
>
>And get: "error: 'B' is an inaccessible base of 'D0', 'B'
>is an inaccessible base of 'D1' "
> But when I change the order of inheritance: "class D0 : public B, BB",


This is equivalent to class D0: public B, private BB

>everything works fine.
>Why?
>
>TID, Yuval.


Regards,
-- Zar
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
inaccessible base despite public inheritance Stefan Weber C++ 9 05-29-2007 07:58 AM
inaccessible base despite public inheritance Stefan Weber C++ 2 05-22-2007 06:48 PM
inaccessible base despite public inheritance Stefan Weber C++ 0 05-22-2007 06:28 PM
Copy construction with inaccessible base class copy c-tor Victor Bazarov C++ 15 03-04-2007 03:47 PM
Base class inaccessible due to ambiguity daniel.w.gelder@gmail.com C++ 4 05-04-2005 04:54 PM



Advertisments