Garmaine Staff asked 1 year ago

I am trying to pass a class as a template parameter. But this class has only one mandatory constructor where we have to pass an integer value. So I am trying to find a way to initialize the template's constructor parameter.

#include <iostream>

template <class F>
class Class1 {
    int i = 0;
    F f;
    Class1() { i = f.u; }

class Class2 {
    int u = 5;
    Class2(int j) { u = j; }

int main() {
    Class1 <Class2>c;
    std::cout << c.i << std::endl;

Of course, this gives me an error "Class2 no appropriate default constructor available". Saying that I want to pass different classes with constructors that does not have the same number of parameters in Class1's template , is there a way to initialize the template's constructor? I'm looking for something like Class1 c;