mercredi 25 mars 2015

how to pass a vector of vectors into a function expecting a (raw) pointer to pointers

I have a function that accepts a pointer to pointer to double:



void Foo(double ** m); // expects a 3x3 matrix of doubles


Is it somehow possible, with appropriate casting and whatnot, to pass into this function either a std::vector of std::vectors of double or else an std::array of std::arrays of double? If so, can someone please explain how?



std::vector<std::vector<double>> v(3, std::vector<double>(3));
std::array<std::array<double, 3>, 3> a;


If the function accepted only a pointer to double, this would be possible. (via either v.data() or a.data()). But the pointer to pointer in the function interface makes me think that such a conversion may not be possible.


Thank you,


Aaron


Aucun commentaire:

Enregistrer un commentaire