gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 14:18:39 40 4
gpt4 key购买 nike

下面的代码:

#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/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com