arr - double[X][Y] - X Y - X Y . , . , C, . , , (*) [Y] - Y . , , , . , double**.
- , - . :
void func(double* arr, int w) {
// arr[2][3]
arr[2*w + 3] = ...;
}
double x[6][8] = { ... };
func(&x[0][0], 8);
++, , ( ) , :
template <int W, int H>
inline void func(const double (&arr)[W][H]) {
arr[2][3] = ...;
}
double x[6][8] = { ... };
func(x); // W and H are deduced automatically
, , , - (, new -, ). ++. :
#include <vector>
void func(std::vector<std::vector<double> > arr) {
arr[2][3] = ...;
}
std::vector<std::vector<double> > x(6, std::vector<double>(8));
x[0][0] = ...;
...
func(x);
Boost, MultiArray:
void func(boost::multi_array<double, 2> arr) { // 2 means "2-dimensional"
arr[2][3] = ...;
}
boost::multi_array<double, 2> x(boost::extents[6][8]);
x[0][0] = ...;
...
func(x);
[] , . , , , . :
double x1[8] = { 1, 2, ... };
double x2[8] = { 3, 4, ... };
...
double* x[6] = { x1, x2, ... };
func(x);