473,789 Members | 2,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3848
Dave Rahardja <dr************ *************** *@pobox.comwrot e:
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
2351
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
2175
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 { /* ... */ private:
6
5094
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: class A { };
10
7315
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
11111
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 that touch that label are functions in that code-behind page itself -- nothing on the outside. Basically, it doesn't work. Only when I changed it back to 'protected' in the ascx's cs page, could I modify the text in the label, from within...
6
2569
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 drived; public: base() {cout<<"I am base constructor"<<endl;} virtual void test1() {cout << "i am base virtual method " <<endl;}
5
1961
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 difference between "non-public" and "private"? Help is always appreciated. Thanks, Paul
6
1559
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 nice if there was a way for a class to create a special type of interface, a private one. Private meaning it's not directly exposed at the class level, you need to be explicitly handed a reference to it by the class. Often the encapsulation issue...
4
2954
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 member 'GenericDerivedClassTest.Base.DoSomething()' via a qualifier of type 'GenericDerivedClassTest.Base'; the qualifier must be of type 'GenericDerivedClassTest.TBase<DerivedType>' (or derived from it) Why does it believe the object has to derive...
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10410
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.