This question already has an answer here:
- Can't deduce template type 5 answers
I have the following code, which I cannot get to work:
struct foo {};
foo foo1 = {};
template <foo& F>
class FooClass {};
template <foo& F>
void foobar(FooClass<F> arg) {
}
int main() {
FooClass<foo1> f;
foobar(f);
}
The error is:
main.cpp:14:5: error: no matching function for call to 'foobar'
note: candidate template ignored: substitution failure : deduced non-type template argument does not have the same type as the its corresponding template parameter ('foo' vs 'foo &')
OK, I can understand that. Easy to fix, right? Just prepend an &
:
template <foo& F>
void foobar(FooClass<&F> arg) {
}
Wrong:
note: candidate template ignored: couldn't infer template argument 'F'
Is it at all possible to infer lvalue reference template parameters? If so, how should it be done?
Aucun commentaire:
Enregistrer un commentaire