你怎么能确保一个C++函数可以被调用为
你怎么能确保一个 C++ 函数可以被调用为例如 void foo(int, int) 而不是像 void foo(long, long) 这样的任何其他类型?
回答
添加已删除的模板重载:
template <typename A, typename B> void foo(A, B) = delete;
void foo(int x, int y) {...}
对于任何参数类型,除了int, int.
- `foo(0LL, {});` calls the `int` version with a `long long` and an `int`.
- @user975989 do you then have to do this for all permutations of 3 or more arguments?