home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ukma!darwin.sura.net!dtix!mimsy!sdd.comsat.com!mike
- From: mike@sdd.comsat.com (Mike Stennett)
- Newsgroups: comp.lang.c++
- Subject: Confusion on :: and protected (Simple?)
- Message-ID: <mike.721669287@sdd.comsat.com>
- Date: 13 Nov 92 15:41:27 GMT
- Sender: usenet@sdd.comsat.com (USENET News Admin)
- Distribution: na
- Organization: SDD, COMSAT Labs, Clarksburg, MD
- Lines: 60
-
- This is probably a simple question. I've looked in my manuals and
- read the FAQ and I don't see why the following program does not work.
-
- Can anyone tell me why? (This is obviously a simplified example.)
- Why does the :: operator interfere with the derived class accessing
- the protected function?
-
- 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
-
-
- #include <stddef.h> // For "size_t" type
- #include <iostream.h> // For stream I/O
-
- class foo
- {
- public:
- int x;
-
- protected:
- static int print(const int y) { cout << y << endl; return 1;}
- };
-
- class joe : public foo
- {
- public:
- static int something(int z);
- protected:
- static int print(const int y) { cout << "what" << y << endl; return 1;}
-
- };
-
- int joe::something(int z)
- {
- foo::print(5);
- cout << "Did it." << endl;
- return 1;
- }
-
- main()
- {
- joe xyz;
-
- cout << "Starting Program" << endl;
- xyz.x = 4;
- xyz.something(4);
- cout << "Ending Program" << endl;
- }
-
- --
- Signed: Mike Stennett Domain: mike@sdd.comsat.com
- Phone: +1-301-428-4083 Fax: +1-301-428-7747
- USPS: COMSAT Labs, 22300 COMSAT Drive, Clarksburg, MD 20871
-