I am trying to write a function for a template class that takes a parameter that is a function pointer for a member class inside the private data of a large class. When you call this member, it calls this function in a smaller class. (Invalid right?) To demonstrate, I have a non-working example:
#include <vector>
#include <iostream>
using namespace std;
template <typename T, typename C>
struct MyClass {
template <typename F, typename... A>
auto call_me(F func, A... args) {
return (mContainer.*func) (args...);
}
C mContainer;
};
int main() {
MyClass<int, std::vector<int> > test;;
cout << test.call_me(&std::vector<int>::size) << endl;
test.call_me(&std::vector<int>::insert, test.mContainer.begin(), 4);
return 0;
}
, , , . , size
'Private' ( ) vector
class MyClass
. , , insert ( ), :
.\template.cpp: In function 'int main()':
.\template.cpp:24:71: error: no matching function for call to 'MyClass<int, std::vector<int> >::call_me(<unresolved overloaded function type>, std::vector<int>::iterator, int)'
test.call_me(&std::vector<int>::insert, test.mContainer.begin(), 4);
^
.\template.cpp:10:10: note: candidate: template<class F, class ... A> auto MyClass<T, C>::call_me(F, A ...) [with F = F; A = {A ...}; T = int; C = std::vector<int>]
auto call_me(F func, A... args) { // pass in the function we want to call
^~~~~~~
.\template.cpp:10:10: note: template argument deduction/substitution failed:
.\template.cpp:24:71: note: couldn't deduce template parameter 'F'
test.call_me(&std::vector<int>::insert, test.mContainer.begin(), 4);
, , , , . Variadic, .