473,666 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'B' is an inaccessible base of 'D'

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.

Dec 26 '05 #1
2 47383
<yu*****@gmail. com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.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
Dec 26 '05 #2
On 25 Dec 2005 22:16:51 -0800, yu*****@gmail.c om 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
Dec 26 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1799
by: RR | last post by:
I'm sure this has been answered before but two hours of searching and reading hasn't answered this question for me. Here's a test program: ******************************** class base { public: }; class der : protected base
1
4336
by: Dave | last post by:
Hello NG, Regarding access-declarations and member using-declarations as used to change the access level of an inherited base member... Two things need to be considered when determining an inherited base member's access level in the derived class: its access level in the base class and the type of inheritance (public, protected, or private). After this determination is made, the following possibilities exist for manually changing the...
1
3725
by: a eriksson | last post by:
Why is the call foo(c) below ambiguous when B inherits A privately? I think that that contradicts the first error reported below since B objects are not treated as A objects? class A {}; class B : private A {}; class C : public B, public A {};
2
4413
by: Steven T. Hatton | last post by:
Can somebody explain why making T a friend of either B or C will permit the code to compile? class A{ protected: A(){} }; class T; class B: protected A {protected: B(){}/*friend class T;*/}; class C: public B {public : C(){}/*friend class T;*/}; struct T { A* newA() {return new C();}}; int main() {}
15
2393
by: Victor Bazarov | last post by:
Hello, Take a look at this program: ----------------------------------- class B { B(const B&); B& operator=(const B&); public: B(int);
9
18126
by: Stefan Weber | last post by:
Hi, I have the following header file (named test.h): class Foo { public: Foo(void) {} virtual ~Foo(void) {} };
0
8449
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8360
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8784
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8642
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1777
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.