As part of a larger project, I'm trying to create a simple template function that will take an array and a value, both of the same type, and fill the array with the value. I'm running into the error quoted below:
"specializing member '::Fill_With' requires 'template<>' syntax"
Below is the offending code fragment:
// Simple function to fill an array with a specified value.
template <class T> void Fill_With(T target_array, T value){
int Array_Size = sizeof(target_array) / sizeof(T);
for(int l = 0; l < Array_Size; ++l){
target_array[l] = value;
}
}
int array1[4] = {1,2,3,4}, k = 0;
Fill_With<int>(array1, k);
I've read numerous other forum posts on the error message, but haven't quite been able to figure out what I'm missing. I've read that I need to include a blank "template<>" header before the function declaration but that didn't seem to solve the issue. What am I doing wrong? Thanks!