By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,869 Members | 1,756 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,869 IT Pros & Developers. It's quick & easy.

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

P: 62

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:

Expand|Select|Wrap|Line Numbers
  1. //x.cpp
  2. void read(vector <int> a,vector <int> b,vector < vector <int> > c)
  3. {
  4. //a, b, c are vector variables referencing to the vectors in main of y.cpp
  6. }
  7. //y.cpp
  8. void main()
  9. {
  10.       vector <int> a;
  11.       vector <int> b;
  12.       vector < vector <int> > c;
  14.       read(&a,&b,&c);
  15.       //Sending the reference to read function in x.cpp to modify data in main
  16. }

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..
Feb 11 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,510
you need to indicated that the parameters to read() are pointers to vectors, e.g.
Expand|Select|Wrap|Line Numbers
  1. void read(vector <int> *a,vector <int> *b,vector < vector <int> > *c)
you are using C++ why not use reference parameters?
Feb 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.