Hey all.
I'm trying to study for a C++ test and I just got to the templates section.
I'm trying to run the above code and get:
"error C2670: 'Sqr<T>::doIt' : the function template cannot convert parameter 1 from type 'int [4]'"
can I get some help please (don't forget that I'm new to templates...)
Code:
template <class T>
class Sqr
{
public:
void operator () (T& var)
{
var *= var;
}
void doIt (T* begin, T* end, T& var)
{
for (T* i=begin, int z = 0; i != end; i++, z++)
begin[z]();
}
};
void main ()
{
int arr [] = {2, 3, 4, 5};
for (int i=0; i<4; i++)
cout << arr[i] << ' ';
cout << endl;
Sqr::doIt(arr, arr+4, arr[0]);
for (int i=0; i<4; i++)
cout << arr[i] << ' ';
cout << endl;
}