home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!mcsun!news.funet.fi!funic!nntp.hut.fi!vipunen.hut.fi!mkohtala
- From: mkohtala@lesti.hut.fi (Marko Kohtala)
- Subject: Proposal for default scope
- Message-ID: <mkohtala.726108774@vipunen.hut.fi>
- Sender: usenet@nntp.hut.fi (Usenet pseudouser id)
- Nntp-Posting-Host: lesti.hut.fi
- Reply-To: Marko.Kohtala@hut.fi
- Organization: Helsinki University of Technology, Finland
- Date: 4 Jan 93 00:52:54 GMT
- Lines: 73
-
- While writing the implementations to classes, I have often missed the
- possibility to define a default scope like below:
-
- class Class {
- int var;
- int func1();
- int func2();
- };
-
- Class::{ // This is just syntactic sugar to enclose the implementation
- int var;
- int func1()
- {
- /* ... */
- }
- int func2()
- {
- /* ... */
- }
- }
-
- This would be treated as
-
- class Class {
- static int var;
- int func1();
- int func2();
- };
-
- int Class::var;
- int Class::func1()
- {
- /* ... */
- }
- int Class::func2()
- {
- /* ... */
- }
-
- The point being, that the identifiers to define are searched from the
- specified scope and if not found, reported as not being members of
- Class.
-
- Especially in the case of nested classes this can make the source much
- more readable and easier to write and maintain.
-
- This idea could be extended to apply with compound statements, in
- which case any unmatched identifiers should be searched for in
- enclosing scopes. Also operators `.' and `->' should be implemented in
- addition to `::' to be able to access instance members:
-
- Class::{ /* statement list */ }
- The statements in the list could access by default the static members
- of the Class or in member functions the ancestor Class members. Of
- course, if the referenced variable is not a member, it is searched
- for in enclosing scope.
-
- Class_var.{ /* statement list */ }
- Class_ptr->{ /* statement list */ }
-
- These would access the members in the class instance specified.
-
- I am not really a C++ language expert, so I do not know if there will
- be any conflicts with these additions to the language. At least, if
- there are no conflicts, I think they should be quite easy to implement
- after the details have been well specified (which I have not done, as
- you can see).
-
- Please, tell me if it is possible to include this in the language.
- --
- ---
- Marko Kohtala - INTERNET:Marko.Kohtala@hut.fi, mkohtala@otax.tky.hut.fi
- Student at (not representative of) the Helsinki University of Technology
-