🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by George Beshers Thu, 26 Jan 1989 12:55
Re: g++ 1.32 is lax on protection
#1636
Author: George Beshers
Date: Thu, 26 Jan 1989 12:55
4 lines
566 bytes
I thought that was the point of `protected' vs. `private'.  If you change
to private you get the error.

				beshers@carcvax.brc.uconn.edu
Re: g++ 1.32 is lax on protection
#1662
Author: "Douglas C. Schmidt"
Date: Fri, 27 Jan 1989 09:05
63 lines
1871 bytes
 > I thought that was the point of `protected' vs. `private'.  If you change
 > to private you get the error.
 > 
 > 				beshers@carcvax.brc.uconn.edu

Hi,

I believe you're getting confused by the following (which is
admittedly weird at face value):

----------------------------------------
class foo {
protected:
   int i;
};

main () {
   foo bar;
   
   bar.i = 10; // error, protected members are not
               // visible to objects of the base
               // type.
}

g++ correctly says:

----------------------------------------
In function int main ():
test.c:11: member `i' is a protected member of class `foo'
----------------------------------------

However, the following *is* correct:

----------------------------------------
class foo {
protected:
   int i;
};

class bar : public foo {

public:   
   f () {
      i = 10; // OK, since bar is a derived type
   }
};
----------------------------------------

If you look at the example I showed (from Stroustrup's article, so it
had *better* be correct ;-)), you'll see that 

----------------------------------------
X a;
a.prot
----------------------------------------

is clearly trying to get ahold of the protected member, in the same
illegal sense of my first example above.  After all, ``a is not a Y!''

Does that make any more sense?

Doug
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads