no matching function for call to ‘Dahua::Infra::TFunction2<void, const Json::Value&, int&>::TFunction2(void (CPageDesktop::*)(), CPageDesktop*)’ Dahua::Manager::IConfigManager::Proc(&CPageDesktop::onConfigLocalSmartMotionDetect, this));
时间: 2024-04-15 17:29:03 浏览: 153
根据错误信息来看,你尝试使用 `Dahua::Manager::IConfigManager::Proc()` 函数来注册一个成员函数作为回调函数。然而,编译器报告没有找到匹配的函数调用,这可能是因为参数类型不匹配导致的。
根据错误信息,你正在尝试将 `CPageDesktop::onConfigLocalSmartMotionDetect` 作为回调函数,它的类型似乎是 `void (CPageDesktop::*)()`。然而,`Dahua::Manager::IConfigManager::Proc()` 函数的参数类型是 `void (*)(const Json::Value&, int&)`,即一个普通函数指针。
为了解决这个问题,你需要使用适当的转换来将成员函数指针转换为普通函数指针。通常,可以使用一个静态的中间函数来作为转发函数。以下是一个示例:
```cpp
class CPageDesktop {
public:
static void onConfigLocalSmartMotionDetectWrapper(const Json::Value& value, int& result) {
CPageDesktop* instance = reinterpret_cast<CPageDesktop*>(value.asInt64());
instance->onConfigLocalSmartMotionDetect();
}
void onConfigLocalSmartMotionDetect() {
// 实现逻辑
}
void registerCallback() {
Dahua::Manager::IConfigManager::Proc(&CPageDesktop::onConfigLocalSmartMotionDetectWrapper, reinterpret_cast<int64_t>(this));
}
};
```
在上述代码中,我们创建了一个名为 `onConfigLocalSmartMotionDetectWrapper` 的静态中间函数。这个函数会将 `CPageDesktop` 类的实例指针传递给成员函数 `onConfigLocalSmartMotionDetect()` 进行调用。
然后,在 `registerCallback()` 函数中,我们使用 `onConfigLocalSmartMotionDetectWrapper` 作为回调函数进行注册,同时使用 `reinterpret_cast` 将 `this` 指针转换为整数类型的参数传递给中间函数。
通过这种方式,你可以将成员函数指针转换为普通函数指针,并成功注册为回调函数。请根据你的实际情况进行调整和修改。
阅读全文
相关推荐
















