home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!mcsun!ieunet!tcdcs!unix1.tcd.ie!ghawkins
- From: ghawkins@unix1.tcd.ie (George C. Hawkins)
- Subject: Not supposed to use static variables in member fns?
- Message-ID: <ghawkins.725838896@unix1.tcd.ie>
- Sender: usenet@cs.tcd.ie (NN required at ashe.cs.tcd.ie)
- Nntp-Posting-Host: unix1.tcd.ie
- Organization: Trinity College, Dublin
- Date: Thu, 31 Dec 1992 21:54:56 GMT
- Lines: 34
-
-
- If a member function wants to remember a value between calls to it
- then it must store that value in a varaible visible to all member
- functions. Is this right? I was doing:
-
- class Foo {
- void bar;
- }
-
- void Foo::bar()
- {
- static int remember;
-
- // etc.
- }
-
- But was rather upset to find that all instances of Foo shared the
- same 'remember'. I generally use g++ but I ran the above through
- cfront and the way it produces the C code you can see this must be
- true. I find this quite surprising, does C++ save you from using
- global variables at one level by allowing you to pack things up
- into objects only to force you into using variables that are visible
- to all the members within an object.
-
- Yours,
-
-
- George.
-
- --
- george lives at:
- ___________________________________________________________________________
- | ghawkins@unix1.tcd.ie (mostly) | ghawkins@vax1.tcd.ie (sometimes) |
- ---------------------------------------------------------------------------
-