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

Error about inaccessable class

In the code below gcc says

test.cpp: In constructor `SingleInfoDialog::SingleInfoDialog(const
PlayableSetBase&)':
test.cpp:2: error: `class PlayableSetBase' is inaccessible
test.cpp:24: error: within this context

Obviosly gcc does not manage to pass the parameter of type const
PlayableSetBase& to the constructor of InfoDialog because there is a
private base class with the same name. Is this really not allowed?
Marcel
-----
class PlayableSetBase
{
};

class OwnedPlayableSet
: public PlayableSetBase
{public:
OwnedPlayableSet(const PlayableSetBase& r);
};
class InfoDialog
// a member is not sufficient because of the destruction sequence
: private OwnedPlayableSet
{protected:
InfoDialog(const PlayableSetBase& key)
: OwnedPlayableSet(key)
{}
};

class SingleInfoDialog
: public InfoDialog
{public:
SingleInfoDialog(const PlayableSetBase& key)
: InfoDialog(key) // <-- !!!
{}
};
Nov 18 '08 #1
3 5252
Marcel Müller wrote:
In the code below gcc says

test.cpp: In constructor `SingleInfoDialog::SingleInfoDialog(const
PlayableSetBase&)':
test.cpp:2: error: `class PlayableSetBase' is inaccessible
test.cpp:24: error: within this context

Obviosly gcc does not manage to pass the parameter of type const
PlayableSetBase& to the constructor of InfoDialog because there is a
private base class with the same name. Is this really not allowed?
It's probably a quirk of the lookup rules, which can be exacerbated by
g++'s inability to interpret them correctly. Try supplying '::', like I
show below.
>

Marcel
-----
class PlayableSetBase
{
};

class OwnedPlayableSet
: public PlayableSetBase
{public:
OwnedPlayableSet(const PlayableSetBase& r);
};
class InfoDialog
// a member is not sufficient because of the destruction sequence
: private OwnedPlayableSet
{protected:
InfoDialog(const PlayableSetBase& key)
: OwnedPlayableSet(key)
{}
};

class SingleInfoDialog
: public InfoDialog
{public:
SingleInfoDialog(const PlayableSetBase& key)
Try replacing this with

SingleInfoDialog(const ::PlayableSetBase& key)
: InfoDialog(key) // <-- !!!
{}
};
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 18 '08 #2
Marcel Müller wrote:
In the code below gcc says

test.cpp: In constructor `SingleInfoDialog::SingleInfoDialog(const
PlayableSetBase&)':
test.cpp:2: error: `class PlayableSetBase' is inaccessible
test.cpp:24: error: within this context

Obviosly gcc does not manage to pass the parameter of type const
PlayableSetBase& to the constructor of InfoDialog because there is a
private base class with the same name. Is this really not allowed?
There's not just a private base class with that name, but also the name
of that base class is implicitly introduced into the derived class'
scope (it is called "base class name injection"). Class
'PlayableSetBase' is a base class of class 'OwnedPlayableSet', which
means that 'PlayableSetBase' is injected into the 'OwnedPlayableSet'
scope, as if an invisible typedef declaration was there

class OwnedPlayableSet
: public PlayableSetBase
{ public:
...
typedef ::PlayableSetBase PlayableSetBase;
...
};

Now, whenever you use the unqualified 'PlayableSetBase' in any derived
class, it actually refers not to the file-scope name, but to that
class-scope name implicitly declared in 'OwnedPlayableSet'.

In your example, 'InfoDialog' inherits from 'OwnedPlayableSet'
privately, meaning that now 'PlayableSetBase' is private in
'InfoDialog'. And finally, you are trying to access the private
'PlayableSetBase' from 'SingleInfoDialog', which causes the error.

To fix the error, tell the compiler that you want to refer to the global
'PlayableSetBase' name, not the inherited private 'PlayableSetBase' name.

class SingleInfoDialog
: public InfoDialog
{public:
SingleInfoDialog(const ::PlayableSetBase& key)
: InfoDialog(key)
{}
};
>
-----
class PlayableSetBase
{
};

class OwnedPlayableSet
: public PlayableSetBase
{public:
OwnedPlayableSet(const PlayableSetBase& r);
};
class InfoDialog
// a member is not sufficient because of the destruction sequence
: private OwnedPlayableSet
{protected:
InfoDialog(const PlayableSetBase& key)
: OwnedPlayableSet(key)
{}
};

class SingleInfoDialog
: public InfoDialog
{public:
SingleInfoDialog(const PlayableSetBase& key)
: InfoDialog(key) // <-- !!!
{}
};
--
Best regards,
Andrey Tarasevich
Nov 18 '08 #3
Hi!

Andrey Tarasevich wrote:
Marcel Müller wrote:
>In the code below gcc says

test.cpp: In constructor `SingleInfoDialog::SingleInfoDialog(const
PlayableSetBase&)':
test.cpp:2: error: `class PlayableSetBase' is inaccessible
test.cpp:24: error: within this context

Obviosly gcc does not manage to pass the parameter of type const
PlayableSetBase& to the constructor of InfoDialog because there is a
private base class with the same name. Is this really not allowed?

There's not just a private base class with that name, but also the name
of that base class is implicitly introduced into the derived class'
scope (it is called "base class name injection"). Class
'PlayableSetBase' is a base class of class 'OwnedPlayableSet', which
means that 'PlayableSetBase' is injected into the 'OwnedPlayableSet'
scope, as if an invisible typedef declaration was there
[...]

Thanks! This was the decisive hint.

I was a bit confused because the error came at the line with the copy
constructor invocation rather that the functions argument list.

To fix the error, tell the compiler that you want to refer to the global
'PlayableSetBase' name, not the inherited private 'PlayableSetBase' name.

class SingleInfoDialog
: public InfoDialog
{public:
SingleInfoDialog(const ::PlayableSetBase& key)
: InfoDialog(key)
{}
};
That works as expected.

I only wonder a bit why

SingleInfoDialog::SingleInfoDialog(const PlayableSetBase& key) {}

does not give a similar error (assuming a suitable default constructor
of InfoDialog). Types of member function arguments are normally resolved
from within the class scope too.
Marcel
Nov 21 '08 #4

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

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
1
by: cmelnick | last post by:
I created an interface, IMyInterface and placed it in namespace MyPackage. Something like this: namespace MyPackage { interface IMyInterface { // Stuff } } This interface as well as some...
6
by: WindAndWaves | last post by:
Hi Gurus The page below has a strange error. It seems to be working very well, just when you enter 8 or 9 for day, month or year then you get an error. I really have no idea where that is...
7
by: VB Programmer | last post by:
(Using Whidbey, but I don't think it matters.) I keep getting this error: System.NullReferenceException: Object reference not set to an instance of an object. Here is the line it's happening...
2
by: amita | last post by:
when i am writing a program in c# using windows app I am getting this error message as System.Windows.Forms.Control.Text is inaccessable due to its protection level. In the design window when i...
1
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly,...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
6
by: sadegh | last post by:
Hi I have a problem with my program in VC++6 When I compile it, the following errors are listed. I spend a lot of time on the groups.google.com to find its reason, but none of comments could...
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.