"RSH" <way_beyond_oops@yahoo.comwrote in message
news:eCNsYLDiHHA.1216@TK2MSFTNGP03.phx.gbl...
Quote:
Peter,
>
Thanks for the reply. Sorry about that.
>
I do want to have the objects to be added to the list on instantiation...I
just didn't know how to represent that.
There are a number of ways to implement something like that. Without
knowing more about your specific intent, preferences, etc. I can't offer
advice on a particular implementation to choose. However, here's one
example of doing what you want:
class BaseClass
{
static private List<BaseClass_grbcInstances;
public BaseClass()
{
_grbcInstances.Add(this);
}
public void Remove()
{
_grbcInstances.Remove(this);
}
}
The BaseClass can then provide methods for manipulating, searching, etc. the
list of objects. Note that you need to provide an explicit "Remove" method
to ensure that objects are actually released when you want them to be. This
puts the onus on you to figure out when you're actually done with an object,
at least as it relates to the master list of objects. I have seen mentions
of something called a "weak reference" that may or may not help you around
this issue; I don't know enough about weak references to offer you advice on
that.
Finally, I agree with Jon's statement about the possibility of using virtual
methods to deal with per-type behaviors. It's unusual to need to know the
actual type of an object and while I took the shortcut of simply answering
the direct question you asked, I agree that it's more likely that whatever
reason you think you need the type for, that can be more properly addressed
using virtual methods.
Pete