If a class has a static member variable, then every instance of the class uses the SAME static member variable.
Imagine a class:
1 2 3 4 5
|
class person
{
public:
string name;
};
|
You could make an object of type
person, and set their
name variable to something.
You could make another object of type
person, and set their
name variable to something different.
1 2 3 4 5
|
person firstPerson;
firstPerson.name = "Mike";
person secondPerson;
secondPerson.name = "Sally";
|
Two different objects, each with their own independent
name member variable.
If we change the class like this:
1 2 3 4 5
|
class person
{
public:
static string name;
};
|
then EVERY person object we create will share one
name member variable. They will all use the same one. If you change the
name of one person object, you change the name of ALL of them, because they all share the same
name member variable, because it is a static member variable.