Created
May 21, 2019 02:01
-
-
Save a2gs/0a27d25431a3eaa514f6d742547eb4c7 to your computer and use it in GitHub Desktop.
Template parameter
This file contains 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; | |
void print1(int a[5]) | |
{ | |
for (int i =0; i < 5; i++) | |
cout << a[i] << endl; | |
} | |
template<class T, int N> | |
void print2(T (&a)[N]) | |
{ | |
for (int i =0; i < N; i++) | |
cout << a[i] << endl; | |
} | |
int main() | |
{ | |
int x[] = { 1 , 2 , 3}; | |
print1(x); // esperava 5 ?! erro! | |
print2(x); //ok | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
1
2
3
-1077213008
-1218105356
1
2
3