Here is an example using function objects.
class FooBase
{
public:
template< typename FunctorType >
std::vector<int> getMany(FunctorType const & functor, int n)
{
std::vector<int> e;
int i = 0;
e.resize(n);
for (std::vector<int>::iterator it = e.begin(); it!=e.end(); ++it) {
*it = functor( i++ );
}
}
};
With this, client code can call getMany using lambdas (c++11) or create their own function objects.
auto callMoo = [this] (char i) { return Moo(i); };
getMany(callMoo, n);