【发布时间】:2019-06-04 05:04:23
【问题描述】:
我需要获取涉及 SFINAE 的重载模板函数的地址。这种情况的一个很好的例子是 boost::asio::spawn found here...
https://www.boost.org/doc/libs/1_70_0/doc/html/boost_asio/reference/spawn.html
我如何找到这个特定实例的地址...
template<
typename Function,
typename Executor>
void spawn(
const Executor & ex,
Function && function,
const boost::coroutines::attributes & attributes = boost::coroutines::attributes(),
typename enable_if< is_executor< Executor >::value >::type* = 0);
我试过这个没有成功...
using Exec = boost::asio::io_context;
using Func = std::function<void(boost::asio::yield_context)>;
void (*addr)(Exec, Func) = boost::asio::spawn;
【问题讨论】:
-
使用 static_cast。
-
该函数接受 四个 参数。你不能将它的地址分配给一个指向函数的指针,因为它不是这样的。这与模板无关。尝试使用带有默认参数的普通函数。