home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13483 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1001 b   |  33 lines

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