473,385 Members | 1,748 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.

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 18088
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.