Using Pointers on Vectors in C++ (Call by Reference from Funtion to Function)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nabh4u
    New Member
    • Jan 2007
    • 62

    Using Pointers on Vectors in C++ (Call by Reference from Funtion to Function)

    Hi,

    I have a problem referencing to Vectors using pointers i.e. I am not able to use "call by reference" on vector variables.

    I have a "read()" function in "x.cpp" and "main()" in "y.cpp". I have 3 vector variables in Main(). I want the read function to read the values into the vector using the address I send of the vectors..

    Sample code:

    Code:
    //x.cpp
    void read(vector <int> a,vector <int> b,vector < vector <int> > c)
    {
    //a, b, c are vector variables referencing to the vectors in main of y.cpp
         
    }
    //y.cpp
    void main()
    {
          vector <int> a;
          vector <int> b;
          vector < vector <int> > c;
          
          read(&a,&b,&c);
          //Sending the reference to read function in x.cpp to modify data in main
    }

    I got a LNK#### error where # are numbers.

    How do I get this program of mine to read values into the vectors by using references?

    I need help as soon as possible

    Thank You in Advance..
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    you need to indicated that the parameters to read() are pointers to vectors, e.g.
    Code:
    void read(vector <int> *a,vector <int> *b,vector < vector <int> > *c)
    you are using C++ why not use reference parameters?

    Comment

    Working...