是什么导致了 std::bad_function_call?
我见过很少 问题引用std::bad_function_call
异常,但一直无法通过谷歌搜索找出导致此异常的原因。
什么样的行为会导致此异常?你能给我一些没有其他语义问题的最小例子吗?
I've seen a few questions that refer to the std::bad_function_call
exception, but haven't been able to find out any by Googling about what causes this exception.
What kind of behavior is supposed to cause this exception? Can you give me minimal examples that don't have other semantic problems also going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当然 - 最简单的方法是尝试调用空的
std::function
。Sure- the easiest is where you try to call a
std::function
that's empty.就我而言,问题出在捕获列表中。我有一个递归 lambda 函数。
捕获列表中 f_build 中缺少
&
会生成错误的调用。In my case, the problem was in the capture list. I have a recursive lambda function.
Missing
&
from f_build in the capture list generates a bad call.“在没有调用目标的情况下执行函数调用会引发以下类型的异常
std::bad_function_call"
不属于我......其 C++ 标准库的 Nicolai Josuttis Pundit
"Performing a function call without having a target to call throws an exception of type
std::bad_function_call"
No credits to me....its Nicolai Josuttis Pundit of C++ Standard Lib
调用临时函数也可能抛出:
但这取决于编译器(vc++ 抛出,g++ 不会)。
Call of a temporary function also can throw:
But this depend on compiler (vc++ throws, g++ not).