Reputation: 403
The below code:
#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;
}
gives the error:
error: reference to overloaded function could not be resolved; did you mean to call it?
Can anyone suggest what's wrong here and how to overcome it?
Upvotes: 5
Views: 2522
Reputation: 180500
hOccupy
is an overloaded function. That means in order to get the address of it, you need to specify which overload you want the address of. For instance, if you want the pointer to point to
hError_t hOccupy(int* numB, const void* f, int bS, size_t dyn);
then you can use
auto f = static_cast<hError_t (*)(int, const void*, int, size_t)>(&hOccupy);
If you want f
to refer to the overload set, then you can do that using a lambda like
auto f = [](int* numB, auto f, int bS, size_t dyn){ return hOccupy(numB, f, bS, dyn); };
Upvotes: 5
Reputation: 51825
To complement the answer provided by NathanOliver, if you instead wanted a pointer to a specific instance of your template overload, you need to specify the type (T) in your code.
For example:
decltype(&hOccupy<int*>) f = &hOccupy;
Without a specified type, your decltype
statement is ill-formed.
Upvotes: 2