wildcard function pointer non-type template parameter

前端 未结 2 1986
清酒与你
清酒与你 2021-01-28 11:34

Templates can take non-type function pointer parameters, but there is a problem if all possible function pointer parameters are accepted, example:

void dummy()
{         


        
2条回答
  •  一个人的身影
    2021-01-28 12:26

    A better solution for your particular problem would be to simply take only the function type as a template argument and the item as an ordinary function argument. You can also use type deduction instead of explicitly specifying which argument types are used:

    void dummy()
    {
    }
    
    template 
    void proxy(FT fp)
    {
      fp();
    }
    
    int main()
    {
      proxy(fp);
    
      return 0;
    }
    

提交回复
热议问题