By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,293 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,293 IT Pros & Developers. It's quick & easy.

inaccessible base despite public inheritance

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.