473,387 Members | 1,535 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,387 software developers and data experts.

inaccessible base despite public inheritance

Hi,

I have the following header file (named test.h):

class Foo
{
public:
Foo(void) {}
virtual ~Foo(void) {}
};

class Bar : public Foo
{
public:
Bar(void) {}
virtual ~Bar(void) {}
};

with a very simple cpp file:

#include "test.h"

int main() {
Foo* f = new Bar();
}

This compiles with Visual Studio 2005, but with g++ 4.1.1 I get an
error:

bash-3.00$ test.cpp:4: error: Foo is an inaccessible base of Bar

Acutally, I know that this error message occurs when doing something
like "class Bar : private Foo" (i.e. inherit the code but withouth
polymorphism). But I obviously declared to use public inheritance.
Does anybody see the problem?

Thanks,

Stefan

May 22 '07 #1
9 18089
Stefan Weber wrote:
I have the following header file (named test.h):

class Foo
{
public:
Foo(void) {}
virtual ~Foo(void) {}
};

class Bar : public Foo
{
public:
Bar(void) {}
virtual ~Bar(void) {}
};

with a very simple cpp file:

#include "test.h"

int main() {
Foo* f = new Bar();
}

This compiles with Visual Studio 2005, but with g++ 4.1.1 I get an
error:

bash-3.00$ test.cpp:4: error: Foo is an inaccessible base of Bar

Acutally, I know that this error message occurs when doing something
like "class Bar : private Foo" (i.e. inherit the code but withouth
polymorphism). But I obviously declared to use public inheritance.
Does anybody see the problem?
The only /potential/ problem is the name of the header file.

Put the code you posted in the same cpp file and compile it again
(comment out 'with a very...' and the '#include'). If it compiles,
the problem isn't in the code. If it doesn't, you're SOL. Get
a better compiler.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 22 '07 #2

"Stefan Weber" <st**********@gmail.comwrote in message
news:11**********************@z24g2000prd.googlegr oups.com...
Hi,

I have the following header file (named test.h):

class Foo
{
public:
Foo(void) {}
virtual ~Foo(void) {}
};

class Bar : public Foo
{
public:
Bar(void) {}
virtual ~Bar(void) {}
};

with a very simple cpp file:

#include "test.h"

int main() {
Foo* f = new Bar();
}

This compiles with Visual Studio 2005, but with g++ 4.1.1 I get an
error:

bash-3.00$ test.cpp:4: error: Foo is an inaccessible base of Bar

Acutally, I know that this error message occurs when doing something
like "class Bar : private Foo" (i.e. inherit the code but withouth
polymorphism). But I obviously declared to use public inheritance.
Does anybody see the problem?
The only thing I see unusual is the use of void as a parameter type. In
C++, don't use "(void)" when there's no parameter, just use "()". I don't
know if it's an error, but it's certainly not the norm.

-Howard

May 22 '07 #3
Howard wrote:
[..]
The only thing I see unusual is the use of void as a parameter type.
Unfortunately, it's not as unusual as it ought to be.
In C++, don't use "(void)" when there's no parameter, just use "()".
I agree, it's a better style IMO, but they are definitely the same
AFA function declarations are concerned.
I don't know if it's an error, but it's certainly not the norm.
It's perfectly fine from the syntactic point of view.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 22 '07 #4
Stefan Weber wrote:
Hi,

I have the following header file (named test.h):

class Foo
{
public:
Foo(void) {}
virtual ~Foo(void) {}
};

class Bar : public Foo
{
public:
Bar(void) {}
virtual ~Bar(void) {}
};

with a very simple cpp file:

#include "test.h"

int main() {
Foo* f = new Bar();
}

This compiles with Visual Studio 2005, but with g++ 4.1.1 I get an
error:

bash-3.00$ test.cpp:4: error: Foo is an inaccessible base of Bar

Acutally, I know that this error message occurs when doing something
like "class Bar : private Foo" (i.e. inherit the code but withouth
polymorphism). But I obviously declared to use public inheritance.
Does anybody see the problem?

Thanks,

Stefan
Are you sure this is the complete story? How exactly do you compile your
files with gcc 4.1.1?

F
May 22 '07 #5
Your code looks fine, are you sure there's no other test.h file in the
way ?
Acutally, I know that this error message occurs when doing something
like "class Bar : private Foo" (i.e. inherit the code but withouth
polymorphism).
Deriving a class with the keyword "private" doesn't imply anything
about polymorphism. It just means that private members of the base
class will not be visible from the derived class.
- Guillaume.

May 22 '07 #6
Your code looks fine, are you sure there's no other test.h file in the
way ?
Acutally, I know that this error message occurs when doing something
like "class Bar : private Foo" (i.e. inherit the code but withouth
polymorphism).
Deriving a class with the keyword "private" doesn't imply anything
about polymorphism. It just means that private members of the base
class will not be visible from the derived class.
- Guillaume.

May 22 '07 #7
On May 22, 6:44 pm, "Howard" <alic...@hotmail.comwrote:
C++, don't use "(void)" when there's no parameter, just >use "()". I don't
know if it's an error, but it's certainly not the norm.
its not an error.

May 22 '07 #8
Your code looks fine, are you sure there's no other test.h file in the
way ?
Acutally, I know that this error message occurs when doing something
like "class Bar : private Foo" (i.e. inherit the code but withouth
polymorphism).
Deriving a class with the keyword "private" doesn't imply anything
about polymorphism. It just means that private members of the base
class will not be visible from the derived class.
- Guillaume.

May 22 '07 #9
The only /potential/ problem is the name of the header file.
>
Put the code you posted in the same cpp file and compile it again
(comment out 'with a very...' and the '#include'). If it compiles,
the problem isn't in the code. If it doesn't, you're SOL. Get
a better compiler.
Thanks for the hint, this helped :) So the actual code obviously was
correct.

May 29 '07 #10

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

Similar topics

2
by: Tony Johansson | last post by:
Hello experts! My question is what advantage and disadvantage have public inheritance. The answer that I have to this is that sometimes it is an advantage to let a client have access to...
2
by: yuvalif | last post by:
Hi All, I fail to compile the following code (well, not exactly that code...): class BB { }; class B { public:
2
by: bob | last post by:
let's say you do public inheritance on a class. then you do public inheritance on the subclass. in the grandchild, is a protected member in the original class still accessible?
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);
2
by: Stefan Weber | last post by:
Hi, I have the following header file (named test.h): class Foo { public: Foo(void) {} virtual ~Foo(void) {} };
3
by: Immortal Nephi | last post by:
I write three classes. The name of class are A, B, and C. Class A and Class B are inaccessible to the client. Class C is accessible to the client. Class B has inheritance to Class A. The...
4
by: RinKaMeAri | last post by:
Hi! Could you imagine any way to block access to the base class public methods? Here is an example: class B: def public_method(): pass class A(B): def public_a_method():
11
by: Michael MK | last post by:
Hi there all, Im curently working on my course work and got stuck on of the questions. I have three classes : car, minibus and truck. I want the car to be my base and minibus, truck to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.