c++ - 从不同的 cpp 调用回调函数会导致 bad_function_call
问题描述
我目前正在开发一个 OpenCV 项目,我想从不同的 cpp 调用 main.cpp 中的回调函数。
我面临的问题是,当我想调用该函数时,我得到一个 bad_function_call,因为回调函数为空。
我的 main.cpp 看起来像这样:
PointDetection *detect;
detect->houghCallback = [hPublisher] (std::vector<cv::Vec4i> data) {
//do something
};
我的 PointDetector.hpp,它包含在 PointDetector.cpp 中:
std::function <void (std::vector<cv::Vec4i> data) houghCallback;
我调用函数的 PointDetector.cpp 如下所示:
void PointDetector::houghDetectCb(int status, void *userData) {
std::vector<cv::Vec4i> houghPointsResult;
PointDetector *self = static_cast<PointDetector *>(userData); //This includes every variable in the hpp except the houghCallback for some reason
self->houghCallback(houghPointsResult); //This causes the bad_function_call because houghCallback is Null
}
有人知道是否可以像这样调用回调?
解决方案
我找到了解决方案:我在实际 GPU 操作之前调用了 stream.enqueqeHostCallback (请参阅此问题:cuda 流:流执行后未调用回调)
推荐阅读
- tortoisegit - 同步对话框显示了一些提交,但 git 声称远程分支是最新的
- angular - 为将 karma.conf.js 修改为幻像的 Angular 应用程序运行单元测试无法识别打字稿规范文件
- c++ - 具有默认成员值和不完整类型的模板扩展的编译器差异
- python - 如何将 NFS 共享挂载到 JupyterHub 中的衍生容器?
- python - 如何在字典中使用不同数字的键的多个值?
- c# - 利用资源字典中的 WindowStyle 并将按钮添加到应用程序中的 ControlPresenter
- r - 基于 R 中另一个表的值在表中首次出现
- azure - Microsoft Bot Framework - 从 Azure 应用服务调用外部 Web API
- python - 如何使用库文件作为独立文件创建 setup.py
- activemq-artemis - 在 Artemis Webconsole 中设置标题的问题