List of void * type

Discussion in 'C++' started by Stub, Nov 9, 2003.

  1. Stub

    Stub Guest

    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?
     
    Stub, Nov 9, 2003
    #1
    1. Advertising

  2. Stub

    Rolf Magnus Guest

    Stub wrote:

    > 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.
     
    Rolf Magnus, Nov 9, 2003
    #2
    1. Advertising

  3. Stub

    Cy Edmunds Guest

    "Stub" <> wrote in message
    news:xsyrb.40697$...
    > 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.

    --
    Cy
    http://home.rochester.rr.com/cyhome/
     
    Cy Edmunds, Nov 9, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ollej Reemt
    Replies:
    7
    Views:
    552
    Jack Klein
    Apr 22, 2005
  2. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    796
    The Real OS/2 Guy
    Oct 28, 2003
  3. Replies:
    5
    Views:
    843
    S.Tobias
    Jul 22, 2005
  4. Abhishek
    Replies:
    12
    Views:
    812
    Eric Sosman
    Jan 30, 2006
  5. Replies:
    1
    Views:
    413
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page