Reputation: 327
It is possible to pass 1D vector to a function as follows:
#include <vector>
void f(double *vec) {
// do stuff..
}
int main() {
std::vector<double> vec = {1,2,3};
f(&vec[0]);
}
Is there any equivalent for passing vector<vector<double>>
to f(double **vec)
?
I'm joining two pieces of code together and it would be cumbersome to rewrite whole code to use either vectors or arrays.
Upvotes: 2
Views: 474
Reputation: 238461
No, you cannot pass a pointer to an element of std::vector<std::vector<double>>
into a function accepting double**
because the type of those elements is std::vector<double>
and not double*
. You would have to transform it into a std::vector<double*>
to do the same.
Upvotes: 2