|
-
November 12th, 2010, 11:31 AM
#1
Static variable in non-static member function?
Hello, new here and hope to get some help on this problem.
I need to have a variable in a member function of a class that maintains its value throughout the lifetime of each instance of the class. If I understand correctly, if the member function is not static, then each instance of the class will have its own copy of the function. If so then all I needed to do is to declare a static variable in that member function. But when I ran the code it did not work. The static variable seems to be shared by all instances of the class, even though it is inside a non-static member function. Maybe I just misunderstand the whole concept. Please help!
In Brief: How do I make a variable inside a member function static but not shared among all the instances of the class (each instance has its own copy)?
Thank you!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|