home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!rational.com!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Subject: Re: Confusion on :: and protected (Simple?)
- Message-ID: <rmartin.722274669@thor>
- Sender: news@rational.com
- Organization: Rational
- References: <mike.721669287@sdd.comsat.com>
- Distribution: na
- Date: Fri, 20 Nov 1992 15:51:09 GMT
- Lines: 50
-
- 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).
-
- 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?
-
- E&S try to justify this in the last paragraph of page 254.
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-