For debugging, I would like to add some counter variables to my class. But it would be nice to do this without changing the header to cause a lot of recompilation.
If Ive correctly understood the keyword, the following two snippets would be exactly the same. Assuming, of course, that there is only one instance.
class FooA
{
public:
FooA() : count(0) {}
~FooA() {}
void update()
{
++count;
}
private:
int count;
};
vs.
class FooB
{
public:
FooB() {}
~FooB() {}
void update()
{
static int count = 0;
++count;
}
};
In FooA, you can get an account anywhere in the class, as well as inflate the title, since the variable must be deleted when it is no longer needed.
FooB , . . , , , FooB , .
: , , , , .