C+++ function



  • What's the difference between the two instructions?

     void func() {}
     int main()
     {
        func(); // <--
        func;   // <--
     }
    


  • The first line is a function, and the second one does nothing.

    The second line can be compared to the following code:

    int n = 0;
    n;
    

    That is the expression that results in the expression itself. In the case of a n this is the variable value. nand in your case this address is a function func♪ Your example is as follows:

    auto f = func;   // <--
    f();
    

    Here, we copyed the address. func(this is what you've had, but we've completed the attribution, and then we funcindirectly through f




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2