home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18732 < prev    next >
Encoding:
Text File  |  1993-01-06  |  1.6 KB  |  48 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!gatech!udel!rochester!rocksanne!news
  3. From: Heliotis.ROCH803@xerox.com (Jim Heliotis)
  4. Subject: Re: Not supposed to use static variables in me
  5. Message-ID: <1993Jan5.143723.7928@spectrum.xerox.com>
  6. Sender: news@spectrum.xerox.com
  7. Reply-To: Heliotis.ROCH803@xerox.com
  8. Organization: Xerox Corporation, Webster NY
  9. References: <ghawkins.725838896@unix1.tcd.ie>
  10. Date: Tue, 5 Jan 1993 14:37:23 GMT
  11. Lines: 35
  12.  
  13. In article 725838896@unix1.tcd.ie, ghawkins@unix1.tcd.ie (George C. Hawkins) writes:
  14. >
  15. >If a member function wants to remember a value between calls to it
  16. >then it must store that value in a varaible visible to all member
  17. >functions. Is this right? I was doing:
  18. >
  19. >class Foo {
  20. >    void bar;
  21. >}
  22. >
  23. >void Foo::bar()
  24. >{
  25. >    static int remember;
  26. >
  27. >    // etc.
  28. >}
  29. >
  30. >But was rather upset to find that all instances of Foo shared the
  31. >same 'remember'.
  32.  
  33.  
  34. I have not yet seen the answer to this question that I consider most
  35. straightforward.  You should declare "remember" as a member variable
  36. (non-static).  The only disadvantage to that, possibly, is that any
  37. member function can access it that way.
  38.  
  39.  
  40. ============================================================================
  41. Jim Heliotis                                       Voice Phone: 716-383-7410
  42. Xerox Corporation                                   FAX Phone:  716-383-7395
  43. 435 W. Commercial St.                                     Mail Stop: 803-01A
  44. East Rochester, NY 14445              Electronic Mail: JEH.ROCH803@Xerox.COM
  45. ============================================================================
  46.  
  47.  
  48.