473,325 Members | 2,872 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,325 software developers and data experts.

Private inheritance vs internal class declaration

MSVC seems to have a tough time with this program:
struct A
{
struct L
{};
};

struct B: private A::L
{
struct L
{};
};

struct C: public B::L // <-- Error: see below
{
};

int main()
{
C c;
}

---
error C2247: 'A::L' not accessible because 'B' uses 'private' to inherit from
'A::L'

It seems to me that A::L and B::L are completely different classes, and the
fact that B inherits privately from A::L should effectively hide the A::L
interface from B's users.

It also seems that MSVC is the only compiler complaining about this. Both g++
and Metrowerks CodeWarrior accept the code. Is this an MSVC bug, or am I
getting the standard mixed up?

-dr
Jun 13 '07 #1
1 3834
Dave Rahardja <dr****************************@pobox.comwrote:
MSVC seems to have a tough time with this program:
struct A
{
struct L
{};
};

struct B: private A::L
{
struct L
{};
};

struct C: public B::L // <-- Error: see below
{
};

int main()
{
C c;
}

---
error C2247: 'A::L' not accessible because 'B' uses 'private' to inherit from
'A::L'

It seems to me that A::L and B::L are completely different classes, and the
fact that B inherits privately from A::L should effectively hide the A::L
interface from B's users.

It also seems that MSVC is the only compiler complaining about this. Both g++
and Metrowerks CodeWarrior accept the code. Is this an MSVC bug, or am I
getting the standard mixed up?
It compiles with Comeau Online, so I am inclined to say it is an MSVC
bug.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jun 13 '07 #2

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

Similar topics

19
by: qazmlp | last post by:
class base { // other members public: virtual ~base() { } virtual void virtualMethod1()=0 ; virtual void virtualMethod2()=0 ; virtual void virtualMethod3()=0 ;
5
by: Marcin Kalicinski | last post by:
Hi, Because public inheritance should be used to model is-a relationship, is it evil from a design point of view to disallow some operations from base class? class Derived: public Base { /*...
6
by: Jonathan Potter | last post by:
Hi, I was wondering if someone could explain something to me. We recently upgraded to a new C++ compiler and found some old code wouldn't compile. Boiled down, the code that causes the error is:...
10
by: Martin Vorbrodt | last post by:
Example code in one of my books intrigues me: class B { public: B* Clone() const { B* p = DoClone(); assert(typeid(*p) == typeid(*this)); return p; }
4
by: Jason Shohet | last post by:
A label on an ascx control has a corresponding declaration in the c# code-behind page. I was curious what would happen if I made that declaration 'PRIVATE' instead of 'PROTECTED'. The only things...
6
by: pragtideep | last post by:
I am trying to understand the following code kindly help me #include<iostream> using namespace std; class base { private: ~base() {cout << "This is base destructor"<<endl ;} friend class...
5
by: Paul | last post by:
Hello All, I am new to C# and dot NET in general. The book I am reading uses the term "non-public." I suspect that they don't mean "private", otherwise they would have said so. What is the...
6
by: WXS | last post by:
I know this sounds contrary to the idea of an interface, but read this and see what you think. ----------------------------------------------------------------------------------------- It would be...
4
by: Israel | last post by:
Can someone explain to me why I get a compiler error with the following code on the line obj.DoSomething()? but if cast the object I get no error. The error I get is: Cannot access protected...
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...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: 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
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.