home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16641 < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.7 KB  |  63 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!rational.com!thor!rmartin
  3. From: rmartin@thor.Rational.COM (Bob Martin)
  4. Subject: Re: Confusion on :: and protected (Simple?)
  5. Message-ID: <rmartin.722274669@thor>
  6. Sender: news@rational.com
  7. Organization: Rational
  8. References: <mike.721669287@sdd.comsat.com>
  9. Distribution: na
  10. Date: Fri, 20 Nov 1992 15:51:09 GMT
  11. Lines: 50
  12.  
  13. mike@sdd.comsat.com (Mike Stennett) writes:
  14.  
  15. |I tried to compile with both DEC's cxx 1.0 and GNU's g++ 2.2.2 but got 
  16. |the following errors:
  17.  
  18. |[39] cxx test.C
  19. |test.C:24: error: In this statement, "foo::print" is not accessible.
  20. |Compilation terminated with errors.
  21. |[40] g++ test.C
  22. |test.C: In function `int  static joe::something (int)':
  23. |test.C:24: method `int  static foo::print (int)' is protected
  24.  
  25.  
  26. |class foo 
  27. |{
  28. |protected:
  29. |    static int print(const int y) { cout << y << endl; return 1;}
  30. |};
  31.  
  32. |class  joe : public foo
  33. |{
  34. |public:
  35. |   static int something(int z);
  36. |};
  37.  
  38. |int joe::something(int z)
  39. |{
  40. |    foo::print(5);
  41.      ^^^^^^^^^^^^^^^    This is the line with the error.
  42. |}
  43.  
  44. ARM 11.5 (p253) says that member functions of derived classes can only
  45. access protected members of base classes "through a pointer to,
  46. reference to, or object of the derived class (or any class derived
  47. from that class). 
  48.  
  49. However, you can do this:
  50.  
  51.     this->foo::print(5); 
  52.  
  53. This is allowable since you are accessing foo::print through a pointer
  54. to a joe (this).  Wierd huh?
  55.  
  56. E&S try to justify this in the last paragraph of page 254.  
  57.  
  58. --
  59. Robert Martin                        Training courses offered in:
  60. R. C. M. Consulting                       Object Oriented Analysis
  61. 2080 Cranbrook Rd.                        Object Oriented Design
  62. Green Oaks, Il 60048 (708) 918-1004       C++
  63.