I've been stumped on this for a while, and distilled a simple example of my error message. Is there some way to make this work? Am I just missing a "template" or "typename" somewhere?
#include <cstdint>
template<typename T, typename J>
struct silly
{
const void (*f)(T,J);
};
template<typename T, typename J, silly<T, J> aSilly>
struct sillier
{
const uint32_t something;
};
void dumb_func(uint32_t i, uint32_t j)
{
return;
}
constexpr silly<uint32_t, uint32_t> mySilly{ .f = dumb_func };
using silliest = sillier<uint32_t, uint32_t, mySilly>;
int main()
{
return 2;
}
g++ spits out:
g++ -std=c++2a ugh.cpp
ugh.cpp:20:51: error: invalid conversion from ‘void (*)(uint32_t, uint32_t)’ {aka ‘void (*)(unsigned int, unsigned int)’} to ‘const void (*)(unsigned int, unsigned int)’ [-fpermissive]
20 | constexpr silly<uint32_t, uint32_t> mySilly{ .f = dumb_func };
| ^~~~~~~~~
| |
| void (*)(uint32_t, uint32_t) {aka void (*)(unsigned int, unsigned int)}
ugh.cpp:20:51: error: ‘dumb_func’ is not a valid template argument of type ‘const void (*)(unsigned int, unsigned int)’ because ‘dumb_func’ is not a variable
I've tried reading through https://en.cppreference.com/w/cpp/language/template_parameters but I'm out of my template depth here. The actual use case for this has T and J being something like std::array<float, ?> and then sillier<T, J, silly<T, J>> inherits from some other more general class, and has overrides which call functions like f so that everything gets inlined into specialized functions for a given instance of silly<T, J>.