"Lowen" <Lo****@import. com> wrote in message news:<bh******* ***********@bgt nsc05-news.ops.worldn et.att.net>...
It's my understanding a static member variable will be one instance among
all objects created from it, and static member functions only access static
variables. When coding, I am still not sure how to decide if to declare a
member of a class "static"? Is there some tips on this? thanks!
One of my instructors had this "trick" for deciding when to use
static and when to use non-static.
Think of the class definition as a factory, and the objects (the
instances of the class) as the cars produced in that factory.
If the information is about the car (the instance) then it should
be "per car" and a non-static member.
If the information is about the factory (the class) and not about
individual cars, then it should be static.
So, to say it another way, the static members should be information
that applies to the entire set of objects, no matter how many there
are, and the non-static should be information about inidividual
objects.
So, for example, a count of cars the factory had produced so far
would be static. The mileage on an individual car would be non-static.
Socks