I want to create CPtrList that contains a variety of different pointers.
pos1 points to a int
pos2 points to a CString
pos2 points to a TypeA
etc.
Later when I traverse the list I want to determine what the pointer actually
points to.
Pseudo code
For each pos in list:
If pos pointer is int then do int pointer stuff
If pos pointer is CString then do CString pointer stuff
If pos pointer is TypeA then do TypeA pointer stuff
Next pos:
Is there a way to do this? Is it considered ok with repect to C++
structured programming styles? Right now I have several different pointers
and the number of local structures etc is growing. This would be a big help
if I did not have to keep up with what the pointer actually points to when
the list is created.
Much thanks from Paul in ATL
First suggestion - are you sure you need to do something like this?
Have you carefully considered your design to be certain that this is
the best way to accomplish what you want to accomplish? I can't see
why it would be necessary to keep a list of such disparate pointer
types.
That said, you're going to run into trouble keeping track of the
type of pointer stored, and I don't believe there will be any way
around doing some sort of enumeration. Given that, though, you could
store void* and then cast as appropriate.