且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在C ++中将函数模板作为参数传递

更新时间:2022-04-23 00:04:49

std :: max 有多个重载,因此编译器无法确定要调用哪个。

std::max has multiple overloads, so the compiler is unable to determine which one you want to call. Use static_cast to disambiguate and your code will compile.

static_cast<int const&(*)(int const&, int const&)>(std::max)

[](int a, int b){ return std::max(a, b); }

现场演示