在C中,如果我想创建一个矩阵结构,我将使用:struct matrix {
int col, row;
double data[1]; // I want the matrix entries stored
// right after this struct}然后我就可以把它分配给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;}现在我用C+做等价物了吗?编辑:我想知道在C+中实现矩阵类的规范方法。
3 回答
红糖糍粑
TA贡献1815条经验 获得超6个赞
// These tend to be fast and allocated on the stack.matrix<3,3> M;
// These are slower but more flexible and partially allocated on the heap matrix M(3,3);
- 3 回答
- 0 关注
- 574 浏览
添加回答
举报
0/150
提交
取消