C ++ vector <vector <double >> twice **

I am trying to pass a type variable vector<vector<double> >to a function F(double ** mat, int m, int n). Function F comes from another library, so I have no way to change it. Can someone give me some hints of this? Thank.

+5
source share
3 answers

vector<vector<double> >and double**- completely different types. But this function can be served using another vector that stores several double pointers:

vector<vector<double> > thing = ...;
vector<double*> ptrs (thing.size());
for (unsigned i=0, e=ptrs.size(); i<e; ++i) {
    ptrs[i] = &(thing[i][0]); // assuming !thing[i].empty()
}
your_function(&ptrs[0],...);

One reason this works is because std :: vector ensures that all elements are stored sequentially in memory.

+8
source

, vector<vector<double> > ,

, , , , .

, ++ , .

+1

< < double → m. m , . , temp 2dim, .

+1
source

All Articles