Default value of a function pointer in C++

后端 未结 5 1352
说谎
说谎 2020-12-18 05:18

What is the default value of a function pointer in C++? (Apparently it can\'t be NULL, so what is it?)

How is this program supposed to behave and why?

5条回答
  •  时光取名叫无心
    2020-12-18 05:50

    A function pointer can be NULL and you may assign NULL to it. Have a look here for instance:

    #include 
    
    using namespace std;
    
    struct S { void (*f)(); };
    
    int main()
    {
        S s = S();
        s.f = NULL;
        return 0;
    }
    

    I believe the way you call the constructor of the structure(with ()), f will be NULL.

提交回复
热议问题