Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Compiler messages with pub/prot/priv inheritance

Reply
Thread Tools

Compiler messages with pub/prot/priv inheritance

 
 
Edd
Guest
Posts: n/a
 
      01-06-2006
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."
http://www.velocityreviews.com/forums/(E-Mail Removed) | - Henry Rollins
 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      01-06-2006

"Edd" <(E-Mail Removed)> wrote in message
news:dpkepo$oa3$(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Edd
Guest
Posts: n/a
 
      01-06-2006
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."
(E-Mail Removed) | - Henry Rollins
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
There are no more messages on this topic. All messages in this topic may have expired or been deleted Coach 02 Computer Support 1 03-12-2007 03:44 PM
absence of router advertisment messages in reponse to roiuter solicitation messages sonia sainani Software 0 10-20-2006 09:20 AM
i sent 2 messages about double messages monique Computer Support 0 11-27-2004 07:18 PM
will all these messages cause a problem . I am a new subscriber and my computer is downloading 100,000 messages. Will this cause any kind of a problem with my ability to store other items?? Camille White Camille White Computer Support 9 11-08-2004 01:13 AM
Private access modifier and Inheritance (Inheritance implementation in Java) maxw_cc Java 1 12-21-2003 11:38 AM



Advertisments