Redian新闻
>
二维数组参数怎么传好?
avatar
二维数组参数怎么传好?# JobHunting - 待字闺中
s*f
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];
avatar
a*m
2
弄个类管理下,或者传指针和行长度。
avatar
h*s
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];

avatar
s*f
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);

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。