Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save allen501pc/1543397 to your computer and use it in GitHub Desktop.
Save allen501pc/1543397 to your computer and use it in GitHub Desktop.
用2維陣列template傳遞不定大小陣列Array
#include <iostream>
using namespace std;
/*
* @Function:
template<typename T,size_t M,size_t N>
void fnPrint2DArray(T (&arr)[M][N])
* @Brief: Print the content of 2D Array.
* @Input: 2D array.
* @Output: None.
*/
template<typename T,size_t M,size_t N>
void fnPrint2DArray(T (&arr)[M][N])
{
for(size_t i=0;i<M;++i)
{
for(size_t j=0; j<N; ++j)
{
cout << arr[i][j] << " ";
}
cout << endl;
}
}
int main(int argc, char * argv[])
{
int arr2D[3][2] = { {1,2},{3,4},{5,6}}; // Create 2D array.
// Print 2D array.
fnPrint2DArray(arr2D);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment