在C中,如果我想创建一个矩阵结构,我会使用:
struct matrix {
int col, row;
double data[1]; // I want the matrix entries stored
// right after this struct
}
Run Code Online (Sandbox Code Playgroud)
然后我可以分配它
matrix* allocate_matrix(int row, int col) {
matrix* m = malloc(sizeof(matrix) + sizeof(double) * (row * col - 1));
m->row = row; m->col = col;
return m;
}
Run Code Online (Sandbox Code Playgroud)
现在我在C++中做等效吗?
编辑:
我想知道在C++中实现矩阵类的方法.