So I’m working with templates in a class that inherits another class and I’m trying to create an instance of the derive class, without using the template. Is there any way to achieve this and how? And how can I set Func f
to be equal to some default value?
#include <iostream>
class PF {};
template<class Func>
class PFC : public PF {
Func f;
public:
PFC()=default;
explicit PFC(const Func& f);
PFC(const int *vals, int cnt);
};
template<class Func>
PFC<Func>::PFC(const Func &f) : PF() {
this->f = f;
}
template<class Func>
PFC<Func>::PFC(const int *overloadedVals, int cnt) {}
int main()
{
int vals[10];
PF *f = new PFC(vals);
delete f;
return 0;
}
Error from CLion syntax checker:
No viable constructor or deduction guide for deduction of template arguments of ‘PFC’, candidate template ignored: couldn’t infer template argument
Error from CLion CMake compilation:
error: class template argument deduction failed:
Error from gcc:
main.cpp: In function ‘int main()’:
main.cpp:25:15: error: expected type-specifier before ‘PFC’
25 | PF *f = new PFC(vals);
| ^~~