我在 Visualstudio 中运行 sonarlint 插件。 我的代码存在一个主要问题,如下所示:
_declspec(dllexport) void GetInformation(void (add)(const char* pCarName))
{
add("N3-988");
add("N3-40");
add("N3-41");
add("N3-428");
}
错误是
cpp:S5205 : Replace this function pointer with a template parameter or a "std::function".
如何解决?
最佳答案
这个错误是一个转移注意力的错误。您输错了函数指针语法,仅此而已。你需要
void (*add)(const char* pCarName)
作为参数类型。 add
是一个函数指针,它在函数体中的使用(add("N3-988");
等)是合适的。
关于c++ - 如何用模板参数或 std::function 替换函数指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66653884/