samedi 29 octobre 2016

Understanding of function pointer syntax in c++

I have two questions

  1. Are both of these declarations of setEvalFunction equivalent for using EvalFunctionPtr = T (*)(const std::vector<T>&);?

    a) void setEvalFunction(const EvalFunctionPtr& evalFunc);
    
    b) void setEvalFunction(T (* const &evalFunc)(const std::vector<T>&));
    
    
  2. What is the difference between the following parameters (since both seem to work fine).

    a) T (* const &evalFunc)(const std::vector<T>&)
    
    b) T (* const &evalFunc)(const std::vector<T>&)&
    
    

I want to have something equivalent to 1 a), i.e. passing a reference to a constant function pointer, but without using some extra definition like using EvalFunctionPtr = ....

Aucun commentaire:

Enregistrer un commentaire