0

Im working on a homework for a class and im not looking for someone to write the code for me but my professor wants us to write a template function and use his already existing code to call the function. the problem im having is his code(posted below) calls the function like this: add_one(x)(y). he also insists that his code has no errors so i dont really know how to write a template function that allows you to call it like this. can anyone tell me how to do this?

my professors code.

int main()
{
 int x = 2;
 int y = 3;
 cout << x << " + " << y << " = " << add_one(x)(y) << endl;

 string s = "Hello";
 string t = "World";
 cout << s << " + " << t << " = " << add_one(s)(t) << endl;
}
  • 6
    Hint: it's not a function with two sets of parenthesis. It's two functions. – Mooing Duck Apr 19 '16 at 17:31
  • Well since this is homework I will only comment. You need to make the return of `add_one` something that you can use `(y)` on. That operation should return `x + y`. – NathanOliver Apr 19 '16 at 17:32
  • 4
    Read http://stackoverflow.com/questions/356950/c-functors-and-their-uses then decide if there's anything you need answered. – Pete Kirkham Apr 19 '16 at 17:35

0 Answers0