Created
December 31, 2011 08:34
-
-
Save allen501pc/1543397 to your computer and use it in GitHub Desktop.
用2維陣列template傳遞不定大小陣列Array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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