* john:
By doing:
void MyClass::MyFunc tion()
{
static int myvar;
...
}
We can defined a function local variable 'myvar' that keeps its value
from call to call (the point is that the variable can not be easily
accessed from outside the function, *that* is what we want to achieve)
But this variable is global to *all* instance of the MyClass class. Is
there an artifact that allow a similar definition but for a variable
that is instance-based.
?
Not really.
But consider that if 'myvar' is to be restricted to a _single_ function,
then it is a local variable.
And if it is to be restricted to a _set_ of member functions, then the
functionality it partakes in is also restricted to that set, so the set
forms its own class. I.e. you can make that set of member functions, plus
variable, a separate class that 'MyClass' inherits from. Or that 'MyClass'
contains an instance variable of.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?