I have here this code.
#include <iostream>
using namespace std;
template <typename T> inline T bigArry(const T data[5])
{
T level = data[0];
for(T item : data) // error C2143: syntax error : missing ',' before ':' (1st)
{ //error C2143: syntax error : missing ';' before '{' (3rd)
if(level<item){ level=item; }
}
return level;
}
int main()
{
int data[5]={//five variables}
cout << bigArry(data);//see reference to function template instantiation 'T bigArry<int>(const T [])' being compiled with [ T=int] (2nd)
return 0;
}
The function bigArry() returns the highest value out of a array of 5 elements.
The problem is that when I use the range-based loop it gives me the errors mentioned in the code. But when I use the usual for, everything goes back to normal. I mean, the syntax to me looks fine, I can't see the problem. I'm using Visual Studio 2010.
The other thing I want to ask is about the inline functions. Currently I'm reading C++ Primer Plus 6th edition. When do I know when a function is too big to be inlined? Is there a standard of how short the code should be? Or, do we use the inline functions when we "think" it's okay?