[英]Calling Callback function from different cpp causes bad_function_call
I'm currently working on an OpenCV project where I want to call a callback function in main.cpp from a different cpp.我目前正在处理一个 OpenCV 项目,我想从不同的 cpp 调用 main.cpp 中的回调函数。
The problem I'm facing is that when I want to call the function I get a bad_function_call because the Callback function is a null.我面临的问题是,当我想调用该函数时,我得到了一个 bad_function_call,因为 Callback 函数为空。
My main.cpp looks like this:我的 main.cpp 看起来像这样:
PointDetection *detect;
detect->houghCallback = [hPublisher] (std::vector<cv::Vec4i> data) {
//do something
};
my PointDetector.hpp, which gets included by the PointDetector.cpp:我的 PointDetector.hpp,它包含在 PointDetector.cpp 中:
std::function <void (std::vector<cv::Vec4i> data) houghCallback;
My PointDetector.cpp, where I call the function looks like this:我在 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
}
Does somebody know if it is possible to call the Callback like this?有人知道是否可以像这样调用回调吗?
我找到了解决方案:我在实际的 GPU 操作之前调用了 stream.enqueqeHostCallback(参见这个问题: cuda 流:流执行后未调用回调)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.