How can I define and pass a pointer to a vector object?

This is a discussion on How can I define and pass a pointer to a vector object? within the C++ Programming forums, part of the General Programming Boards category; Dear all, As my title suggests, if I define the object vec1 by: Code: vector<double> vec1; How can I define ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    48

    Unhappy How can I define and pass a pointer to a vector object?

    Dear all,

    As my title suggests, if I define the object vec1 by:
    Code:
    vector<double> vec1;
    How can I define a pointer to vec1 and pass it to another function? Thanks a lot..

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    May-be
    void f(vector<double> &myVector) ?

    and called:
    f(vec1)

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    you can define the function with a reference argument.

    Code:
    void foo(vector<T> &aVec)
    {//do something with the vector}
    then when you pass the vector object to a function, it will work on the copy. You can ensure it won't change by definint the function argument as
    Code:
     void foo(const vector<T> &aVec)

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    48
    I see. I was not sure whether I should add <.> thing in the function behind vector. Thanks a lot, pals.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to pass function pointer as arg in c++
    By umen242 in forum C++ Programming
    Replies: 13
    Last Post: 10-21-2008, 02:09 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. HowTo increase 1 value to the pointer and pass by ref?
    By Mathsniper in forum C Programming
    Replies: 10
    Last Post: 10-29-2005, 05:21 PM
  4. LISP (DrScheme) any one?
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-31-2004, 11:52 AM
  5. queued signals problem, C programming related
    By Unregistered in forum Linux Programming
    Replies: 3
    Last Post: 01-21-2002, 11:30 PM

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