binary function compile error

Mar 8, 2013 at 2:55pm
Hi,

I wrote a binary function based on existing template:
1
2
3
4
template <class T> struct percentage : binary_function <T,T,double> {
  double operator() (const T& x, const T& y) const
    {return x*1.0/(x+y);}
};

I call it in form of percentage<int>() When I compile, it's indicated:
error C2143: syntax error : missing ',' before '<'
I use VC 2012.

I am confused. Could anyone please tell me where is the error? Thanks!
Mar 8, 2013 at 3:16pm
At what line do you get this error on?
Mar 8, 2013 at 3:19pm
the first line of the template. Do I need a special header to compile it?
Last edited on Mar 8, 2013 at 3:21pm
Mar 8, 2013 at 3:27pm
You will need:

1
2
3
#include <algorithm>

using namespace std;


To use the binary_function
Mar 8, 2013 at 3:30pm
std::binary_function is defined in the <functional> header.
Mar 8, 2013 at 3:40pm
Thanks for the replies. I added std:: and that works. Just forgot this thing... Thanks! :)
Topic archived. No new replies allowed.