home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!doug.cae.wisc.edu!umn.edu!giga.cs.umn.edu!hansen
- From: hansen@giga.cs.umn.edu (David M. Hansen)
- Subject: Re: Confusion on :: and protected (Simple?)
- Message-ID: <1992Nov20.231757.5827@news2.cis.umn.edu>
- Sender: news@news2.cis.umn.edu (Usenet News Administration)
- Nntp-Posting-Host: giga.cs.umn.edu
- Organization: University of Minnesota
- References: <mike.721669287@sdd.comsat.com> <rmartin.722274669@thor>
- Distribution: na
- Date: Fri, 20 Nov 1992 23:17:57 GMT
- Lines: 56
-
- In article <rmartin.722274669@thor>, rmartin@thor.Rational.COM (Bob Martin) writes:
- |> mike@sdd.comsat.com (Mike Stennett) writes:
- |>
-
- [error messages deleted
-
- |>
- |> |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).
-
- Almost. What it says is "A friend or member function of a derived class can
- access a protected static member of a base class."
-
- Notice that foo::print() is static.
-
- The ARM goes on to say "A friend or member function of a derived class can
- access a protected *nonstatic* [emphasis mine] member of one of its base classes
- only through a pointer to, reference to, or object of the derived class (or
- any class derived from that class)."
-
- Mr. Stennett appears to have found a bug in his compilers.
-
- BTW, CenterLine's ObjectCenter 1.1 compiles and executes this code correctly.
-
- |>
- |> 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?
-
- Ummm. joe::something() is also static. Therefore there is no 'this' available.
-
-
- -=Dave
-