c++ - function type vs. function pointer type -


I am trying to understand the difference between the following two blocks of code:

  Zero F (int (* function)) {throw (5); }   

and

  zero (int (int)) {func (5); }   

Both of the following functions work the following way:

  int blah (int a) {cout & lt; & Lt; "Hello" & lt; & Lt; Endl; Return 0; } Int main () {f (blah); Gram (blah); Return 0; }   

However, if I write the following code:

  int (* foo) (int); Int (goo) (int); Foo = blah; Goo = blah;   

I get a compilation error for goo = blah but in the first example, I call the function call g (blah) I can do that which looks like goo = blah why does one work and not another?

In some deceptive ways, you can declare the function to take the function as a parameter (Even if it does not make sense), and the effect parameter is to make the function pointer. The way in which you can declare a function parameter is the same way, which looks like an array, but in fact one The indicator is.

The function argument can be the name of the function, with or without & amp; ; Obviously, your address is if you type in & amp; , then there is an implied function-to-pointer conversion, then it is similar to passing an array, where the implied array-to-pointer conversion means that you have the & amp; Instead of array [0] , write the name of the array only.

The rule does not apply when declaring the variable; int goo (int); (without the unnecessary brackets around goo ) declares a function, not an indicator, and you can not assign it to the function.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -