473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

'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 47349
<yu*****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr 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
Dec 26 '05 #2
On 25 Dec 2005 22:16:51 -0800, yu*****@gmail.com 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
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 {...
1
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...
1
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 {}; ...
2
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;*/};...
15
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.