Change the line
std::map<int, std::function<File*>> createMF;
to
std::map<int, std::function<File*()>> createMF;
The type of the template parameter to instantiate the std::functional
is not a File*
but a function that has no arguments and returns a File*
.
Update
You can simplify your code a little bit using another template. Instead of
File* createMF0(){
return new tFile<0>;
}
File* createMF1(){
return new tFile<1>;
}
File* createMF2(){
return new tFile<2>;
}
File* createMF3(){
return new tFile<3>;
}
You can have just one function:
template <int N>
File* createMF(){
return new tFile<N>;
}
If you do that, the core of main
function needs to be changed to:
// Now for the real stuff
std::map<int, std::function<File*()>> createFunctions;
std::map<int, File*> templateFiles;
createFunctions[0] = createMF<0>;
createFunctions[1] = createMF<1>;
createFunctions[2] = createMF<2>;
createFunctions[3] = createMF<3>;
// Here I'm trying to avoid a switch statement
std::cout << std::endl;
for (int i=0; i <= 3; i++){
std::cout << "i = " << i << std::endl;
templateFiles[i] = createFunctions[i]();
}