home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18097 < prev    next >
Encoding:
Internet Message Format  |  1992-12-16  |  1.8 KB

  1. Path: sparky!uunet!cs.utexas.edu!sun-barr!olivea!spool.mu.edu!umn.edu!csus.edu!netcom.com!erc
  2. From: erc@netcom.com (Eric Smith)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Why not nested functions ?
  5. Keywords: nested functions, c++
  6. Message-ID: <1992Dec16.232309.12886@netcom.com>
  7. Date: 16 Dec 92 23:23:09 GMT
  8. References: <KRISS.92Dec16162433@blues.ibp.fr>
  9. Distribution: comp
  10. Organization: Netcom - Online Communication Services (408 241-9760 guest)
  11. Lines: 26
  12.  
  13. In article <KRISS.92Dec16162433@blues.ibp.fr> grosjean@masi.ibp.fr writes:
  14. >My point is that you can *simulate* nested functions using
  15. >a local class. To call the function you call a member function
  16. >of the local class, you explicitely give the syntaxic context 
  17. >you need for the function copying the automatic variables
  18. >you want to use in local class members variables.
  19. >
  20. >In one word : I *do* it, so it can be done.
  21.  
  22.  
  23. The most important feature of a nested function is that you can call
  24. it from an unrelated function, which has no knowledge of its context.
  25.  
  26. I don't see how this can be simulated without adding it as a feature
  27. to the language, but I don't see any real reason for not adding that
  28. feature.  It sure seems like it would make C++ a much more powerful
  29. language, and that a lot of the most complicated code would be neater
  30. and easier to work with.  It also doesn't seem very hard to implement,
  31. using pointers to stack frame descriptors or something like that.
  32.  
  33. Or is there a way to simulate this feature using objects?  If so, can
  34. someone please explain it clearly or refer us to a clear explanation?
  35. The original poster seems to be describing a way to simulate a very
  36. limited subset of this feature, in which it is necessary for all
  37. functions invoking the nested function to have access to its context,
  38. which sacrifices the biggest advantage of nested functions.
  39.