mercredi 23 août 2017

Overloading operator body contains only one function call

I have this function

int add(int a, int b)
{
  return a+b;
}

And I want to overload the plus operator and I have to options (of course, in this case the plus operator already accomplishes what the following code does)

Option 1:

int operator+(int lhs, int rhs)
{
  return add(a,b);
}

Option 2:

int operator+(int lhs, int rhs)
{
  return a+b;
}

Does any of those definitions have a performance edge over the other? Something to not is that the function I am trying to implement performs a more complicated operation on the elements of an STL container.

Aucun commentaire:

Enregistrer un commentaire