Thread: Plz help me with this requirement...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    5

    Plz help me with this requirement...

    Hi,

    I have 4 classes like A,B,C & D.
    I need to store the objects of these classes in a one-dimensional array kind of data structure so that i can get those objects just by using an index. For instance when i say, array[0] i should get A's object, array[1] should give me the B's object and so on...

    Can you plz suggest a way for doing this??

    Thanks & regards,
    S.Guruprasanna

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    5

    Plz help me with this requirement...

    Hi,

    I have 4 classes like A,B,C & D.
    I need to store the objects of these classes in a one-dimensional array kind of data structure so that i can get those objects just by using an index. For instance when i say, array[0] i should get A's object, array[1] should give me the B's object and so on...

    Can you plz suggest a way for doing this??

    Thanks & regards,
    S.Guruprasanna

  3. #3
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Look up templates/containers

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    You can derive all four classes from a common base class and create an array of baseclass pointers to hold your objects.

    You can do the same with void pointers and casting, but that's ugly.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    or you could go:

    #define A array[0]
    #define B array[1]
    #define C array[2]
    #define D array[3]

    :-D
    "There are three kinds of people in the world...
    Those that can count and those that can't."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  3. plz help me with simple string comparison.
    By MegaManZZ in forum C++ Programming
    Replies: 11
    Last Post: 02-18-2008, 01:11 PM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM