samedi 3 septembre 2016

Using lambdas in template class

I'm trying to use a template class with a lambda function parameter. However, I don't understand how to pass the parameter. Here's what I've tried so far:

#include <iostream>
using namespace std;

template <class F>
class A {
public:

   int f(int i)
   {
       return F(i); //*
   }
};

int main(int argc, const char * argv[]) {
auto f = [](int i){return i+5;};
A<decltype(f)> a;
cout << a.f(5);
return 0;
}

I get an error in the marked line.

Can someone help?

Aucun commentaire:

Enregistrer un commentaire