472,365 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,365 software developers and data experts.

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 "inaccessible" 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*@nunswithcrapguns.net | - Henry Rollins
Jan 6 '06 #1
2 1409

"Edd" <ed*@crapnunswithguns.net> wrote in message
news:dp**********@news6.svr.pol.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
"inaccessible" 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*@nunswithcrapguns.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
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...
10
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...
25
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 -------------...
14
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...
0
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...
7
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...
17
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...
55
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...
0
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.