作者streamaway (Celith)
看板C_and_CPP
標題Re: [語法] 請教 C++ 關於參數傳遞
時間Sat Jul 15 17:55:54 2006
#include<iostream>
using namespace std;
template<typename T,size_t M,size_t N>
void output(T (&array)[M][N]){
for(size_t i=0;i<M;++i){
for(size_t j=0;j<N;++j)
cout<<array[i][j]<<" ";
cout<<endl;
}
}
int main()
{
int a[2][3]={{1,2,3},{4,5,6}};
output(a);
system("pause");
return 0;
}
試試這個方法~可適用於任何型態(要支援operator<<)、任何大小~
不過我不太懂為什麼要用reference...
晚點來問學長 orz....
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 222.250.66.254
→ f5845:因為要傳的東西是指標 07/16 21:34
→ firose:用 reference 就不會有 array-to-pointer 轉換 07/17 16:12
推 luckysky1:GO! 07/14 12:10