home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!destroyer!fmsrl7!ef2007!pt0204.pto.ford.com!fox
- From: fox@pt0204.pto.ford.com (Ken Fox)
- Newsgroups: comp.lang.c++
- Subject: typedefs in the scope of a class
- Date: 16 Nov 1992 23:03:11 GMT
- Organization: Power Train Systems, Ford Motor Company
- Lines: 70
- Distribution: world
- Message-ID: <1e99bfINN3l2@ef2007.efhd.ford.com>
- Reply-To: fox@pt0204.pto.ford.com
- NNTP-Posting-Host: pt0204.pto.ford.com
- Keywords: typedef, scope, name space
-
- I've come across strange behavior (at least to me...) in the interpretation
- of "nested" classes. I want classes stored in files according to functional
- classification, but also I want to place them into a "package," or name
- space that I can control. I thought that I could just create bizzare class
- names and then use typedefs to put them into the scope of a class which would
- serve as my name space... but I'm obviously missing something here because
- this "simple" example won't work.
-
- Could somebody please explain this?
-
- // ======================================================================
- // BAD CODE - Why is this broken?
- // ======================================================================
-
- class myint
- {
- public:
- int value;
- };
-
- class scope
- {
- public:
- typedef int SystemInt;
- typedef myint CustomInt;
- };
-
- int main()
- {
- scope::SystemInt i;
-
- // syntax error on next declaration!
-
- // cfront 2.1: CustomInt is not a type name
- // gcc 2.3: `CustomInt' is not a member of type `scope'
-
- scope::CustomInt j;
- }
-
- // ======================================================================
- // GOOD CODE - Why this and not that?
- // ======================================================================
-
- class scope
- {
- public:
- typedef int SystemInt;
- class CustomInt
- {
- public:
- int value;
- };
- };
-
- int main()
- {
- scope::SystemInt i;
- scope::CustomInt j;
- }
-
- Thanks in advance...
-
- --
-
- Ken Fox (fox@pt0204.pto.ford.com) | My opinions or statements do not
- | represent those of, nor are endorsed by,
- | Ford Motor Company.
- CAD/CAM Technology Section |
- CAD/CAM/CAE Process Integration | "Is this some sort of trick question
- Ford Motor Company | or what?" -- Calvin
-