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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!doug.cae.wisc.edu!umn.edu!giga.cs.umn.edu!hansen
  3. From: hansen@giga.cs.umn.edu (David M. Hansen)
  4. Subject: Re: Confusion on :: and protected (Simple?)
  5. Message-ID: <1992Nov20.231757.5827@news2.cis.umn.edu>
  6. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  7. Nntp-Posting-Host: giga.cs.umn.edu
  8. Organization: University of Minnesota
  9. References: <mike.721669287@sdd.comsat.com> <rmartin.722274669@thor>
  10. Distribution: na
  11. Date: Fri, 20 Nov 1992 23:17:57 GMT
  12. Lines: 56
  13.  
  14. In article <rmartin.722274669@thor>, rmartin@thor.Rational.COM (Bob Martin) writes:
  15. |> mike@sdd.comsat.com (Mike Stennett) writes:
  16. |> 
  17.  
  18. [error messages deleted
  19.  
  20. |> 
  21. |> |class foo 
  22. |> |{
  23. |> |protected:
  24. |> |    static int print(const int y) { cout << y << endl; return 1;}
  25. |> |};
  26. |> 
  27. |> |class  joe : public foo
  28. |> |{
  29. |> |public:
  30. |> |   static int something(int z);
  31. |> |};
  32. |> 
  33. |> |int joe::something(int z)
  34. |> |{
  35. |> |    foo::print(5);
  36. |>      ^^^^^^^^^^^^^^^    This is the line with the error.
  37. |> |}
  38. |> 
  39. |> ARM 11.5 (p253) says that member functions of derived classes can only
  40. |> access protected members of base classes "through a pointer to,
  41. |> reference to, or object of the derived class (or any class derived
  42. |> from that class). 
  43.  
  44. Almost.  What it says is "A friend or member function of a derived class can
  45. access a protected static member of a base class."
  46.  
  47. Notice that foo::print() is static.
  48.  
  49. The ARM goes on to say "A friend or member function of a derived class can 
  50. access a protected *nonstatic* [emphasis mine] member of one of its base classes
  51. only through a pointer to, reference to, or object of the derived class (or
  52. any class derived from that class)."
  53.  
  54. Mr. Stennett appears to have found a bug in his compilers.
  55.  
  56. BTW, CenterLine's ObjectCenter 1.1 compiles and executes this code correctly.
  57.  
  58. |> 
  59. |> However, you can do this:
  60. |> 
  61. |>     this->foo::print(5); 
  62. |> 
  63. |> This is allowable since you are accessing foo::print through a pointer
  64. |> to a joe (this).  Wierd huh?
  65.  
  66. Ummm.  joe::something() is also static.  Therefore there is no 'this' available.
  67.  
  68.  
  69.                     -=Dave
  70.