how to create an array of pointers

This is a discussion on how to create an array of pointers within the C++ Programming forums, part of the General Programming Boards category; I'm trying to create an array of pointers, but I have no idea how. Can anyone show me an example ...

  1. #1
    System-7
    Join Date
    Nov 2005
    Posts
    65

    how to create an array of pointers

    I'm trying to create an array of pointers, but I have no idea how. Can anyone show me an example of how to create one?

    Thanks,

    ...Dan

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    int* Array[1337];
    That's what you mean?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    you mean this:

    char* arrayname[100];

    or:

    int* num[10];
    Hello, testing testing. Everthing is running perfectly...for now

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    int * arrayName[10];

    arrayName is an array of 10 pointers to type int
    You're only born perfect.

  5. #5
    System-7
    Join Date
    Nov 2005
    Posts
    65
    Yeah thanks guys I think that's it.

    Well that was simple

    ...Dan

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Since this is the C++ forum, how about an STL container instead?, eg,
    Code:
    std::vector<int*> foo;
    Code:
    std::deque<int*> bar;
    etc

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Well, if you really want to be C++ about it:
    Code:
    std::vector<std::tr1::shared_ptr<int> > foo;

  8. #8
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Daved
    Well, if you really want to be C++ about it:
    Code:
    std::vector<std::tr1::shared_ptr<int> > foo;
    I see that and raise you
    Code:
    boost::ptr_vector<int> foo;
    less typing == I win!!
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by ChaosEngine
    I see that and raise you
    Code:
    boost::ptr_vector<int> foo;
    less typing == I win!!
    Boost isn't part of the c++ standard just yet

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    >> less typing == I win!!
    Amount of typing isn't an appropriate determinant of victory.

    But you still win.

  11. #11
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Quantum1024
    Boost isn't part of the c++ standard just yet
    technically, neither is TR1.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  12. #12
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Sine array is very similar to pointer, you could also do it like this :
    Code:
    int** i;
    since "int* i" is same as "int i[]"
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  13. #13
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by ElastoManiac
    Sine array is very similar to pointer, you could also do it like this :
    Code:
    int** i;
    since "int* i" is same as "int i[]"
    Heh, I got myself into some hot water with Salem and Dave_Sinkula over that claim on another forum

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating an array of pointers to int[]
    By OkashiiKen in forum C Programming
    Replies: 3
    Last Post: 09-29-2006, 07:48 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM
  4. array of pointers to structs
    By stumon in forum C Programming
    Replies: 7
    Last Post: 03-24-2003, 07:13 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 09:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21