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

  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, 12:52 PM
  5. queued signals problem, C programming related
    By Unregistered in forum Linux Programming
    Replies: 3
    Last Post: 01-22-2002, 12:30 AM