8

How can you make sure a C++ function can be called as e.g. void foo(int, int) but not as any other type like void foo(long, long)?

1 Answers1

17

Add a deleted template overload:

template <typename A, typename B> void foo(A, B) = delete;

void foo(int x, int y) {...}

It will be a better match (causing a error) for any argument types except int, int.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207