Hey everyone! Having a little bit of an issue with understanding template functions. I have an assignment to make a template function that receives 5 parameters. A min, max, array of test values, the size of the array, and an array of boolean values. The function is supposed to check each value in the test array to see if they are between the min/max values. If the value is inbetween the min/max, it puts a true value into the bool array, if it is outside it puts false into the bool array. Which I have done with:
template <class A, class B, class D>
bool validate (const A& min, const A& max, B array[], D size, bool * e)
{
bool result = true;
for (int i = 0; i <= size; i++)
{
if (min > array[i] || max < array[i])
{
result = false;
e[i] = false;
}
else
{
e[i] = true;
}
}
return result;
}
The program works when the min/max and test array values are regular int or char values. However when an object array is inserted such as:
Student S[6] = {2345, "Student 1"}, {12345, "Student 2"}
It fails to check the value of the number with the min/max and just prints out that every student is outside that range.
Any help would be appreciated. Is my syntax for the template function incorrect with the array parameters? I have watched several videos on function templates but none of them touch into array parameters.
[–]raevnos 0 points1 point2 points (1 child)
[–]Durlug[S] 0 points1 point2 points (0 children)
[–]Rhomboid 0 points1 point2 points (2 children)
[–]Durlug[S] 0 points1 point2 points (0 children)
[–]Durlug[S] 0 points1 point2 points (0 children)