Of course, you can create such a vector.
#include <vector> #include <functional> #include <iostream> struct MyClass { int a() { return 1; } int b() { return 2; } }; int main() { std::vector<std::mem_fun_t<int, MyClass> > vec; vec.push_back(std::mem_fun(&MyClass::a)); vec.push_back(std::mem_fun(&MyClass::b)); MyClass x; for (size_t i = 0; i != vec.size(); ++i) { std::cout << vec[i](&x) << '\n'; } }
If you have any problems, read the error message carefully. For example, std::mem_fun can return all kinds of wrappers, depending on what you pass to it.
Or, really, switch to boost or C ++ 0x function .
Edit: with this specific error message, I assume that you are doing something that calls the default constructor for the contained type (e.g. resize or specifying a size using a vector constructor). You cannot use these features.
source share