List of void * type

S

Stub

If building a list of elements of void * type, this way different pointer
types of objects can be put in the list. When you pop data from the list,
can RTTI or any other method be used to determined what pointer type of
object is returned the list?
 
R

Rolf Magnus

Stub said:
If building a list of elements of void * type, this way different
pointer types of objects can be put in the list. When you pop data
from the list, can RTTI or any other method be used to determined what
pointer type of object is returned the list?

No. If you want different types, use a pointer to a polymorphic base
class that points to objects of classes derived from that base class.
RTTI will also only work within such a class hierarchy.
 
C

Cy Edmunds

Stub said:
If building a list of elements of void * type, this way different pointer
types of objects can be put in the list. When you pop data from the list,
can RTTI or any other method be used to determined what pointer type of
object is returned the list?

Use of void* in any other context than very low level hardware or operating
system manipulations is almost always a mistake in C++. Build a list of
reference counted smart pointers to a polymorphic base class and you can
have what you wanted without disabling or even compromising the type system.
And then avoid RTTI in favor of virtual functions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top