SJ said:
Hi:
I have a class which has a static member function. The function
implements something common to all instances.
How can the static member function know all of the (Get access to the
instances' handles) instances?
Thanks in advance for any help
It can't. Not directly, anyway. Static member functions can only access
static member data.
If you're doing something common to all instances, then that should probably
be done by manipulating static member data. Static member data is located
in one place only, not in every instance of the class, so there should be no
need to gain access to all existing instances. They all share the same
static data.
If what you're doing is manipulating some common data value, upon which
individual instances then make *other* calculations (to their own,
non-static, member data), then one solution is to use accessor functions in
the class for the non-static member data. Then, when you ask for one of
those calculated values, you can actually calculate it at that time from the
static data that the static function previously changed.
Or, if there is some reason that you *really* need to access all existing
instances of a class from a static function, then you'll need to somehow
register each instance with a container of some sort, and iterate through
the container to access those instances.
-Howard