【发布时间】:2020-07-03 07:39:58
【问题描述】:
我的Utils 类中有静态方法
这是定义
/*static*/ void Utils::copy_files(void(*progress_callback)(int, int),
std::string const & path_from,
std::string const & path_to)
{
....
}
这里使用
void TV_DepthCamAgent::progress_callback(int count, int copied_file)
{
printf("Progress :: %d :: %d\n", count, copied_file);
}
void TV_DepthCamAgent::foo()
{
...
shared::Utils::copy_files(progress_callback, path_from_copy, path_to_copy);
...
}
这是我得到的错误
“void (TV_DepthCamAgent::)(int count, int mapped_file)”类型的 E0167 参数与“void ()(int, int)”类型的参数不兼容
错误 C3867 'TV_DepthCamAgent::progress_callback':非标准语法;使用 '&' 创建指向成员的指针
我做错了什么?
【问题讨论】:
-
这能回答你的问题吗? How can I pass a class member function as a callback?(假设
progress_callback是非静态的)。基本上,您不能将成员函数作为回调传递,因为您需要一个实例来调用此函数。 -
[OT]:我们现在有
std::filesysem -
TV_DepthCamAgent::progress_callback应该是static,或者copy_files应该被修改。 -
@churill 是的,tnx
-
> 使用 '&' 创建指向成员的指针
标签: c++