c++ - 错误 : reference to overloaded function could not be resolved; did you mean to call it?

标签 c++ c++11 c++17

下面的代码:

#include <cstddef>
using std::size_t;

int hOccupy(int* numB, const void* f, int bS, size_t dyn);

template <class T>
inline int hOccupy(int* numB, T f, int bS, size_t dyn) {
    return hOccupy(numB, reinterpret_cast<const void*>(f), bS, dyn);
}

int main(int argc, char *argv[]) {
    decltype(&hOccupy) f = &hOccupy;
}

给出错误:
 error: reference to overloaded function could not be resolved; did you mean to call it?

任何人都可以建议这里出了什么问题以及如何克服它?

最佳答案

hOccupy是一个重载函数。这意味着为了获得它的地址,您需要指定您想要地址的重载。例如,如果您希望指针指向

hError_t hOccupy(int* numB, const void* f, int bS, size_t dyn);

然后你可以使用
auto f = static_cast<hError_t (*)(int, const void*, int, size_t)>(&hOccupy);

如果你想要 f要引用重载集,那么您可以使用 lambda 之类的
auto f = [](int* numB, auto f, int bS, size_t dyn){ return hOccupy(numB, f, bS, dyn); };

关于c++ - 错误 : reference to overloaded function could not be resolved; did you mean to call it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60096609/

相关文章:

c++ - BFS 段错误

c++ - VS2013 中的类型特征

c++ - 在 C++17 中弃用 `std::result_of` 的原因是什么?

c++ - 如何最好地测试和解包std::if语句中的可选

c++ - 我如何找出下一个 C++ 的特定建议/论文的状态?

c++ - 为什么 vector 分配会改变分配的 vector

c++ - 如何计算减少的值何时达到某个点?

c++ - 无论如何我可以在 visual studio 2005 上使用 visual studio 2015 运行一个已经编码的项目

c++ - 将函数作为参数传递以避免重复代码

c++ - 我什么时候应该使用模板化参数而不是构造参数?