I am having trouble passing a function as an argument to another function. I know this has been addressed already here, but I would appreciate a little more help because I'm having no success. I have tried to adapt this example to my needs:
C++:How to pass reference-to-function into another function?
I'm trying to make my code more readable. I have a huge amount of code and a lot of it is repetitive. For example:
CreateDatabaseEntry( A_key, name_vector, name_vector2, dimension, "_mySuffix" );
CreateDatabaseEntry( B_key, name_vector, name_vector2, dimension, "_mySuffix" ); ...
Let's say I have 26 of these calls in my current main file, one each for B_key, C_key, etc. I would like to move this kind of stuff to functions in a separate "helper" file (helper.cpp/h). For example, into CreateDatabaseEntries().
Problem
Here's my problem. I would have to pass CreateDatabaseEntry into CreateDatabaseEntries. Each call to CreateDatabaseEntry takes different arguments (for example, A_key, then B_key, and so on). I have tried using the example at the link I provided above. But I get "no matching function call" errors. My guess is that I would not get errors if I were calling ONLY one CreateDatabaseEntry. Because I could hard-code "A_key" in the definition of CreateDatabaseEntries. The problem seems to be that I can't generalize the definition of CreateDatabaseEntries to take A_key, B_key, C_key, or whatever.
Also, this is just a simple representation. In practice, I would want to create several "umbrella" functions like CreateDatabaseEntries that would take not only arbitrary A_key, B_key,..., but also arbitrary name_vector and other arguments.
I am a rookie and it is possible that I'm totally barking up the wrong tree. If my explanation makes any sense to anyone, maybe there is a completely different way I could accomplish this? If so, it would be great to know about it. Thanks.