473,583 Members | 3,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compiler messages with pub/prot/priv inheritance

Edd
Hello all,

Please consider:
class Base {
public: int pub;
protected: int prot;
private: int priv;
};

class D1 : public Base { };
class D2 : protected Base { };
class D3 : private Base { };

int main()
{
D1 d1; D2 d2; D3 d3;

d1.pub = 0; //fine - public
d1.prot = 0; //error - protected
d1.priv = 0; //error - private

d2.pub = 0; //error - protected
d2.prot = 0; //error - protected? ('inaccessible' )
d2.priv = 0; //error - private

d3.pub = 0; //error - private? ('inaccessible' )
d3.prot = 0; //error - protected
d3.priv = 0; //error - private

return 0;
}
I would have expected that the error messages for the lines I've tagged with
'inaccessible' to complain about d2.prot being protected and d3.pub being
private, as to my knowledge this is how they would act given their access
specifiers and the types of inheritance used.

However, both MinGW's g++ and VC++ Express 05 use the phrase "inaccessib le" and
avoid "protected" and "private" (which are used in all the other erroneous
cases). Does this mean there's some kind of technical middle-ground between
public/protected/private or am I reading in to these error messages too much?! I
suspect the latter, but I just want to make sure.

Thanks for your patience, and happy new year.

Edd

--
Edd Dawson www.nunswithguns.net | "It's sad when someone you know
To email me, cut the crap. | becomes someone you knew."
ed*@nunswithcra pguns.net | - Henry Rollins
Jan 6 '06 #1
2 1465

"Edd" <ed*@crapnunswi thguns.net> wrote in message
news:dp******** **@news6.svr.po l.co.uk...
Hello all,

Please consider:
class Base {
public: int pub;
protected: int prot;
private: int priv;
};

class D1 : public Base { };
class D2 : protected Base { };
class D3 : private Base { };

int main()
{
D1 d1; D2 d2; D3 d3;

d1.pub = 0; //fine - public
d1.prot = 0; //error - protected
d1.priv = 0; //error - private

d2.pub = 0; //error - protected
d2.prot = 0; //error - protected? ('inaccessible' )
d2.priv = 0; //error - private

d3.pub = 0; //error - private? ('inaccessible' )
d3.prot = 0; //error - protected
d3.priv = 0; //error - private

return 0;
}
I would have expected that the error messages for the lines I've tagged
with 'inaccessible' to complain about d2.prot being protected and d3.pub
being private, as to my knowledge this is how they would act given their
access specifiers and the types of inheritance used.

However, both MinGW's g++ and VC++ Express 05 use the phrase
"inaccessib le" and avoid "protected" and "private" (which are used in all
the other erroneous cases). Does this mean there's some kind of technical
middle-ground between public/protected/private
No.
or am I reading in to these error messages too much?!

Absolutely. The standard cites circumstances (e.g. syntax
error) where a 'diagnostic' is required. There are absolutely
no rules governing what the text of such messages should be.

IOW a compiler can be considered conformant if, for any
kind of diagnostic-required error, it emits "Wrong!" and
nothing else. (Of course such a compiler would not last
long in the marketplace).
I suspect the latter, but I just want to make sure.


Now you are. :-)

Because of the way compilers work, it can sometimes be
difficult to relate a given error message to a specific
construct.

This is solved via experience (with that
particular compiler).

e.g.
-Mike
Jan 6 '06 #2
Edd
Mike Wahler wrote:
Now you are. :-)

Because of the way compilers work, it can sometimes be
difficult to relate a given error message to a specific
construct.


This is what I suspected, thanks Mike. I can sleep easy now!

Edd
--
Edd Dawson www.nunswithguns.net | "It's sad when someone you know
To email me, cut the crap. | becomes someone you knew."
ed*@nunswithcra pguns.net | - Henry Rollins
Jan 6 '06 #3

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

Similar topics

1
3018
by: Rybread | last post by:
Real quick, I have account X and I want a python script that goes in and looks for emails sent from Y and then to save them. i'm trying to go off the swen killer I have listed below (which i took from someone on this NG): import poplib import time print 'Start at', time.asctime()
10
2260
by: forgotten field | last post by:
Hi,how are you? I have been studying C++ by myself, but recently I am having a real problem. I am learning about the basic usage of a doubly linked list using polymorphism. However, I have got the compiler errors which I just can't understand what they mean. I searched the webs for any clues on how to solve the problems. But I've never been...
25
3919
by: Mohd Hanafiah Abdullah | last post by:
Axiomatic Solutions Sdn Bhd announces the availability of AMPC version 1.2. You can purchase AMPC online now at: http://www.axiomsol.com/hedesu/shopping/index.php Major Changes ------------- Version 1.2 supports the MS Windows XP platform, beside Linux x86 and Mac OSX. It also supports the DOUBLE floating point type. Please see the...
14
4288
by: Mark Dufour | last post by:
After nine months of hard work, I am proud to introduce my baby to the world: an experimental Python-to-C++ compiler. It can convert many Python programs into optimized C++ code, without any user intervention such as adding type declarations. It uses rather advanced static type inference techniques to deduce type information by itself. In...
0
1104
by: Mark Dufour | last post by:
Hi all, I have just released Shed Skin 0.0.5. It fixes many bugs and adds many minor features to the Python builtins, most notably, the 'set' class. There have also been some optimizations on the C++ side. Finally, the README now better explains the compiler's limitations, and a TODO file has been added containing open bugs. I would like...
7
1188
by: ndessai | last post by:
Hi All, I discovered following issue with the VC 7.1 compiler regarding the backword compatibility. I created a dll (Redirect.dll) which exposes a function and simply writes some text (say "Hello World") to stderr stream. I also created a driver program (driver.exe) and used the exposed function from the above dll. The driver.exe tries...
17
2525
by: Student | last post by:
Hi All, I have an assignment for my Programming language project to create a compiler that takes a C++ file as input and translate it into the C file. Here I have to take care of inheritance and operator overloading and virtual functions. I mean it should not hamper the C++ meaning. In frank and simple terms i need to implement a small C++...
55
12784
by: Steve | last post by:
I have to develop several large and complex C++ hardware test programs that should work under DOS, most likely with 32-bit DOS extender. Development workstation OS would be Microsoft XP. Quite some time ago I worked in DOS, with Borland BC++ 4.1. I do not have it any more. Which compiler would you recommend me now? Which ones support serious...
0
2043
by: erik.erikson | last post by:
I am getting a compiler error that I can't well explain or even understand the origin of (though I boiled it down close...). Below is a bare-bones example. What I am doing is defining the increment operator in a class and then defining a derived class and using the derived class. When I try to use the increment operator on an instance of...
0
8172
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. ...
0
8320
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7929
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8190
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...
0
6577
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...
1
5697
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5370
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...
1
1424
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1152
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...

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.