Pass a template method as an argument

前端 未结 3 808
后悔当初
后悔当初 2021-01-22 03:58

Could some one help me how to implement this code?

I need to pass a function to another function:

std::cout << process_time(Model::method1) <<         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-22 04:40

    The key is that method1 is a function template:

    template  double method1(std::vector& );
    

    As such, it's not a function... it's a family of functions. process_time expects a single function, so you just have to pass it the one function that you want to use:

    std::cout << process_time(method1) << std::endl;
    

提交回复
热议问题