C++ function types

后端 未结 2 1169
攒了一身酷
攒了一身酷 2020-12-10 01:11

I have a problem understanding function types (they appear e.g. as the Signature template parameter of a std::function):

typedef in         


        
2条回答
  •  萌比男神i
    2020-12-10 01:37

    Here's the relevant paragraph from the Standard. It pretty much speaks for itself.

    8.3.5/10

    A typedef of function type may be used to declare a function but shall not be used to define a function (8.4).

    Example:

    typedef void F();
    F  fv;         // OK: equivalent to void fv();
    F  fv { }      // ill-formed
    void fv() { }  // OK: definition of fv
    

    A typedef of a function type whose declarator includes a cv-qualifier-seq shall be used only to declare the function type for a non-static member function, to declare the function type to which a pointer to member refers, or to declare the top-level function type of another function typedef declaration.

    Example:

    typedef int FIC(int) const;
    FIC f;               // ill-formed: does not declare a member function
    struct S {
      FIC f;             // OK
    };
    FIC S::*pm = &S::f;  // OK
    

提交回复
热议问题