473,320 Members | 1,612 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,320 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 18076
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.