How I can pass lambda expression to c++ template as parameter

后端 未结 4 1867
北海茫月
北海茫月 2020-12-31 08:03

I have a template that accepts a function as an argument.

When I try to pass a lambda expression it does not compile.

typedef int (*func)(int a);
te         


        
4条回答
  •  鱼传尺愫
    2020-12-31 08:42

    This is only because "You cannot use the name or address of a local variable as a template argument.". If you want to make a global static lambda, go refer to http://pfultz2.com/blog/2014/09/02/static-lambda/ you may find what you want.

提交回复
热议问题