simple template compile error

Hi to every one

I have a very small question:
Trying to mimic functors i have a simple compare template function which i try
to pass it to calculate a simple min od 2 doubles

my template is

1
2
3
4
5
6
7
8
9
10
11
12
13
14

template<typename T>
bool cmp(T const& a, T const& b){
	return (a<b);
}

//template<class T>
//bool (*ptrcmp)(T const&,T const&)=cmp;

template <typename T1, typename Compare>
T1 const& minimum(T1 const& a, T1 const& b, Compare cmp) {
return cmp(a,b) ? a : b;
}


when i try to initialize as
1
2

minimum<double,bool>(2.3,4.5,cmp);


i am getting the following build error

error: no matching function for call to 'minimum(double, double, <unresolved overloaded function type>)

what am i doing wrong???

thanks in advance for your help
christos
bool is not a function. The compiler can resolve the template types from the paramater provided, hence you don't need to provide the template paramter: minimum(2.3,4.5,cmp); suffice
I have tried like you suggested and gives me the same compile error
error: no matching function for call to 'minimum(double, double, <unresolved overloaded function type>)'

what do you think?

tnks
You need to call it with cmp<double>. A template is not a type, so you can't call a function with a template without providing the type argument.
Last edited on
thnks it worked !
Topic archived. No new replies allowed.