home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!linac!att!att!allegra!alice!bs
- From: bs@alice.att.com (Bjarne Stroustrup)
- Newsgroups: comp.lang.c++
- Subject: Re: Confusion on :: and protected (Simple?)
- Message-ID: <24266@alice.att.com>
- Date: 21 Nov 92 14:27:30 GMT
- Article-I.D.: alice.24266
- References: <mike.721669287@sdd.comsat.com> <rmartin.722274669@thor>
- Distribution: na
- Organization: AT&T Bell Laboratories, Murray Hill NJ
- Lines: 61
-
-
-
- rmartin@thor.Rational.COM (Bob Martin @ Rational) writes
-
- > mike@sdd.comsat.com (Mike Stennett) writes:
- >
- > |I tried to compile with both DEC's cxx 1.0 and GNU's g++ 2.2.2 but got
- > |the following errors:
- >
- > |[39] cxx test.C
- > |test.C:24: error: In this statement, "foo::print" is not accessible.
- > |Compilation terminated with errors.
- > |[40] g++ test.C
- > |test.C: In function `int static joe::something (int)':
- > |test.C:24: method `int static foo::print (int)' is protected
- >
- > |class foo
- > |{
- > |protected:
- > | static int print(const int y) { cout << y << endl; return 1;}
- > |};
- >
- > |class joe : public foo
- > |{
- > |public:
- > | static int something(int z);
- > |};
- >
- > |int joe::something(int z)
- > |{
- > | foo::print(5);
- > ^^^^^^^^^^^^^^^ This is the line with the error.
- > |}
- >
- > ARM 11.5 (p253) says that member functions of derived classes can only
- > access protected members of base classes "through a pointer to,
- > reference to, or object of the derived class (or any class derived
- > from that class).
-
- Actually, the ARM specifically says NONSTATIC member. That example is
- perfectly legal, so he seems to have found bugs in those compilers.
- On cfront derivatives - and I suspect most C++ compilers - this works
- as written.
-
- > However, you can do this:
- >
- > this->foo::print(5);
- >
- > This is allowable since you are accessing foo::print through a pointer
- > to a joe (this). Wierd huh?
-
- Very, had the first explanation been true. Fortunately it wasn't.
-
- Actually, because joe::something was static there is no `this' pointer
- to use for qualification so ``this->foo::print(5)'' would be an error.
-
- > E&S try to justify this in the last paragraph of page 254.
-
- No. The discussion in 11.5 relates to something completely different.
-
- - BJarne
-