Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,

I have to use many arrays like vector<vector><double> > A1,...An. It is not really a good idea to initialize them one after one, which is what I did. I was wondering if there is a way using a initializing function to make it. Attached is what I am trying to use, yet it does not work.


Thanks,
Paul

C++
void mtx_initialize( vector<vector< double> > A,int row, int col){
     A.resize(row);
     for(int r=0;r<row;r++)   A[r].resize(col);
     return;
}
Posted
Comments
Sergey Alexandrovich Kryukov 19-Jul-13 14:52pm    
Return what?
—SA

1 solution

Assuming your code builds and runs, you have one piece missing.

You need to pass a reference to the vector. As is, you're making and discarding a copy.

C++
void mtx_initialize( vector<vector< double> > & A,int row, int col){
     A.resize(row);
     for(int r=0;r<row;r++)   A[r].resize(col);
     return;
}
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 19-Jul-13 14:53pm    
Exactly; 5 ed.
—SA
ridoy 19-Jul-13 15:15pm    
+5
mars zhang 19-Jul-13 15:21pm    
It works. Thanks a lot for all of you involved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900