home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18611 < prev    next >
Encoding:
Text File  |  1992-12-31  |  1.3 KB  |  46 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!mcsun!ieunet!tcdcs!unix1.tcd.ie!ghawkins
  3. From: ghawkins@unix1.tcd.ie (George C. Hawkins)
  4. Subject: Not supposed to use static variables in member fns?
  5. Message-ID: <ghawkins.725838896@unix1.tcd.ie>
  6. Sender: usenet@cs.tcd.ie (NN required at ashe.cs.tcd.ie)
  7. Nntp-Posting-Host: unix1.tcd.ie
  8. Organization: Trinity College, Dublin
  9. Date: Thu, 31 Dec 1992 21:54:56 GMT
  10. Lines: 34
  11.  
  12.  
  13. If a member function wants to remember a value between calls to it
  14. then it must store that value in a varaible visible to all member
  15. functions. Is this right? I was doing:
  16.  
  17. class Foo {
  18.     void bar;
  19. }
  20.  
  21. void Foo::bar()
  22. {
  23.     static int remember;
  24.  
  25.     // etc.
  26. }
  27.  
  28. But was rather upset to find that all instances of Foo shared the
  29. same 'remember'. I generally use g++ but I ran the above through
  30. cfront and the way it produces the C code you can see this must be
  31. true. I find this quite surprising, does C++ save you from using
  32. global variables at one level by allowing you to pack things up
  33. into objects only to force you into using variables that are visible
  34. to all the members within an object.
  35.  
  36. Yours,
  37.  
  38.  
  39. George.
  40.  
  41. --
  42. george lives at:
  43. ___________________________________________________________________________
  44. |   ghawkins@unix1.tcd.ie (mostly)  |   ghawkins@vax1.tcd.ie (sometimes)  |
  45. ---------------------------------------------------------------------------
  46.