pointers to vectors

This is a discussion on pointers to vectors within the C++ Programming forums, part of the General Programming Boards category; how would i make a pointer to a vector? thx...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    224

    pointers to vectors

    how would i make a pointer to a vector?

    thx

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Post an example of a vector container.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    There aren't very many good reasons to do that. Why do you want to?

    The answer is the same as for any other type.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    Maybe...
    Code:
    vector<int> int_vect;
    vector<int> * ptr_int_vect;
    ptr_int_vect = &int_vect;
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    i wanted to do it so that a class can access a vector located in the main program, without having to pass it as a parameter for every function call.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    That might be one of the few reasons to have a pointer, although if the vector will always be there (and can never be null), then a reference would probably be better.

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    I think it would be tons better to use a global static class or namespace. With a pointer, you'd have to handle allocation, scope, errors and such.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers and vectors
    By larne in forum C Programming
    Replies: 6
    Last Post: 09-12-2008, 10:27 AM
  2. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  3. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  4. Replies: 4
    Last Post: 12-10-2006, 06:08 PM
  5. Points, vectors, matrices
    By subnet_rx in forum Game Programming
    Replies: 17
    Last Post: 01-11-2002, 01:29 PM

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