s*******f 发帖数: 1114 | 1 used for interview.
I don't mean this:
void foo(int m[][const_num])
I want to deal with any size, not just <=const_num.
or this: vector > &vv;
or this: void foo(int *m, int row, int col){m[i * row + j] = ...;}
or this: void foo(int **m)? this cannot accept int m[5][5]; | a********m 发帖数: 15480 | | h*******s 发帖数: 8454 | 3 用vector of vector不是挺好么,为啥非要用数组
可以试试
template
void foo(int m[][width], int height);
【在 s*******f 的大作中提到】 : used for interview. : I don't mean this: : void foo(int m[][const_num]) : I want to deal with any size, not just <=const_num. : or this: vector > &vv; : or this: void foo(int *m, int row, int col){m[i * row + j] = ...;} : or this: void foo(int **m)? this cannot accept int m[5][5];
| s*******f 发帖数: 1114 | 4 u are goddamn right
template
void foo(int m[][width], int height){
for (int i = 0; i < height; ++i){
for (int j = 0; j < width; ++j)
printf("%d ", m[i][j]);
printf("\n");
}
return;
}
int main(){
int a[3][2] = {{1,2},{3,4},{5,6}};
foo<2>(a,3);
}
【在 h*******s 的大作中提到】 : 用vector of vector不是挺好么,为啥非要用数组 : 可以试试 : template : void foo(int m[][width], int height);
|
|