I do not know why it's is not working, is it my function, is it my template.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
template <class first, class size>
first max(first arr[], size N)
{
int max = (max_element(arr,arr+N));
return (max);
}
int main()
{
int l= 6;
int arr[] = {1,23,4,5,6,7};
cout << max(arr,l);
return 0;
}
|
17 34[Error] invalid conversion from 'int*' to 'int' [-fpermissive]
this is one of the errors that keeps popping up.
Last edited on
std::max_element returns an iterator/pointer to the max element. You simply need to dereference it before assigning it to an int on line 8.
int max = *(max_element(arr,arr+N));
Awsome, thank you so much now it works perfectly.