I am new to c++ and am trying to understand how for_each works. So I wanted to see how it works with templates and tried this code but it gives out an error
When I tried to use the for each in the main
it worked as it should have
template <class T>
void forEachTest(T a[])
{
for (int x : a)
cout << x << endl;
}
int main()
{
int a[5] = { 10, 50, 30, 40, 20 };
forEachTest(a);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire