在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 關注
- 616 瀏覽
添加回答
舉報
0/150
提交
取消
