home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13517 < prev    next >
Encoding:
Internet Message Format  |  1992-09-10  |  1.3 KB

  1. Xref: sparky comp.lang.c++:13517 gnu.g++.help:1217
  2. Path: sparky!uunet!dtix!darwin.sura.net!wupost!sdd.hp.com!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!bu.edu!ai-lab!prep.ai.mit.edu!gnulists
  3. From: steve@taumet.com (Steve Clamage)
  4. Newsgroups: comp.lang.c++,gnu.g++.help
  5. Subject: Re: Variable Declarations
  6. Keywords: variables, constructors
  7. Message-ID: <gnusenet1992Sep10.170948.641@taumet.com>
  8. Date: 10 Sep 92 17:09:48 GMT
  9. References: <u895217.716089910@bruny>
  10. Followup-To: comp.lang.c++,gnu.g++.help
  11. Organization: TauMetric Corporation
  12. Lines: 21
  13. Approved: info-gnu@prep.ai.mit.edu
  14. To: gnu-g++-announce@uunet.uu.net
  15.  
  16. u895217@bruny.cc.utas.edu.au (Scott Marshall) writes:
  17.  
  18. |I need a little advice on using C++. When given the following code, would
  19. |the variable being declared (and initialised) be re-initialised on every
  20. |iteration?
  21.  
  22. |    char buf[whatever];
  23. |    f.getline(buf, whatever);
  24. |    while (buf[0] != '#') {
  25. |        String s = buf;
  26. |        if (s.contains("int") ...
  27. |        else ...
  28. |        f.getline(buf, whatever); }
  29.  
  30. Local object 's' will be newly constructed at the top of the loop
  31. for each iteration, and destroyed at the bottom of the loop.  The
  32. braces make a new scope and ensure these semantics.
  33. -- 
  34.  
  35. Steve Clamage, TauMetric Corp, steve@taumet.com
  36. Vice Chair, ANSI C++ Committee, X3J16
  37.