Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pointer Question

0 views
Skip to first unread message

Paul Baker

unread,
May 12, 2002, 2:52:22 PM5/12/02
to
Newbee question...

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


jeasonzhao

unread,
May 12, 2002, 9:59:46 PM5/12/02
to
The pointer can not identified the type of the value,but you can use the
RTTI to determinate .the RTTI use some rset resource in you program.The
alternative is appending a extra field to the pointer to indentified the
type.
Please pardon my weak english.


Craig Powers

unread,
May 14, 2002, 9:45:03 AM5/14/02
to

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.

0 new messages