home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / cplus / 1962 < prev    next >
Encoding:
Text File  |  1993-01-03  |  2.3 KB  |  86 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!mcsun!news.funet.fi!funic!nntp.hut.fi!vipunen.hut.fi!mkohtala
  3. From: mkohtala@lesti.hut.fi (Marko Kohtala)
  4. Subject: Proposal for default scope
  5. Message-ID: <mkohtala.726108774@vipunen.hut.fi>
  6. Sender: usenet@nntp.hut.fi (Usenet pseudouser id)
  7. Nntp-Posting-Host: lesti.hut.fi
  8. Reply-To: Marko.Kohtala@hut.fi
  9. Organization: Helsinki University of Technology, Finland
  10. Date:  4 Jan 93 00:52:54 GMT
  11. Lines: 73
  12.  
  13. While writing the implementations to classes, I have often missed the
  14. possibility to define a default scope like below:
  15.  
  16. class Class { 
  17.   int var;
  18.   int func1();
  19.   int func2();
  20. };
  21.  
  22. Class::{    // This is just syntactic sugar to enclose the implementation
  23.   int var;
  24.   int func1()
  25.   {
  26.     /* ... */
  27.   }
  28.   int func2()
  29.   {
  30.     /* ... */
  31.   }
  32. }
  33.  
  34. This would be treated as
  35.  
  36. class Class { 
  37.   static int var;
  38.   int func1();
  39.   int func2();
  40. };
  41.  
  42. int Class::var;
  43. int Class::func1()
  44. {
  45.   /* ... */
  46. }
  47. int Class::func2()
  48. {
  49.   /* ... */
  50. }
  51.  
  52. The point being, that the identifiers to define are searched from the
  53. specified scope and if not found, reported as not being members of
  54. Class.
  55.  
  56. Especially in the case of nested classes this can make the source much
  57. more readable and easier to write and maintain.
  58.  
  59. This idea could be extended to apply with compound statements, in
  60. which case any unmatched identifiers should be searched for in
  61. enclosing scopes. Also operators `.' and `->' should be implemented in
  62. addition to `::' to be able to access instance members:
  63.  
  64. Class::{ /* statement list */ }
  65.     The statements in the list could access by default the static members
  66.     of the Class or in member functions the ancestor Class members. Of
  67.     course, if the referenced variable is not a member, it is searched
  68.     for in enclosing scope.
  69.  
  70. Class_var.{ /* statement list */ }    
  71. Class_ptr->{ /* statement list */ }
  72.  
  73.     These would access the members in the class instance specified.
  74.  
  75. I am not really a C++ language expert, so I do not know if there will
  76. be any conflicts with these additions to the language. At least, if
  77. there are no conflicts, I think they should be quite easy to implement
  78. after the details have been well specified (which I have not done, as
  79. you can see). 
  80.  
  81. Please, tell me if it is possible to include this in the language.
  82. -- 
  83. ---
  84. Marko Kohtala - INTERNET:Marko.Kohtala@hut.fi, mkohtala@otax.tky.hut.fi
  85. Student at (not representative of) the Helsinki University of Technology
  86.