|
-
November 12th, 2010, 02:51 PM
#9
Re: Static variable in non-static member function?
 Originally Posted by acppdummy
The variable I was having problem with was a bool type that tells the function whether it is being called for the very first time (i.e. reading in the very first number). If true then initialize the min and max to the current value.
Consider whether it might be better to change the design so that you read in everything first, and only then compute mins and maxes using std::min_element, std::max_element, or std::minmax_element.
However, if you wish to keep your current design but want to make a variable visible only to this one function that's easy enough: create a struct or class to live inside your class which contains a single bool private member, and have it implement the method. You can optionally add the method to your outer class's public interface and just pass it along if you like.
Another possibility would be maintaining a count of the number of elements read so far. This is general enough that it might make sense to have it be visible outside the reading function, but could also be tested for whether or not it's 0 inside the reading function.
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
|