【发布时间】:2025-12-11 05:05:02
【问题描述】:
当函数接受模板参数时,需要异步运行函数。下面的代码无法编译,有什么帮助吗?
template<typename T>
void say(int n, T t) {
cout << " say: " << n << " " << t << endl;
}
template<typename F, typename... Ts>
inline auto reallyAsync(F&& f, Ts&&... params){
return std::async(
std::launch::async,
std::forward<F>(f),
std::forward<Ts>(params)...);
}
int main() {
int n = 10; float x = 100;
say(n, x); // works
reallyAsync(&say, n, x) ; // does not work
}
【问题讨论】:
-
这将有助于添加编译器抛出的错误
-
@Stormenet 或使用了哪个编译器。
标签: c++ multithreading asynchronous