c++ - Two styles of syntax for parameter taking a function? -


Reading of Alex Allen's tutorial on function pointer (), in which the function describes the syntax to get the argument:

/ P>

  void doSomething (int (* GetNumber) (player p) = myFunct {}  

Then I was reading Quick C ++, which was The syntax shows:

  Maps & lt; String, vector & lt; Int & gt; & Gt; Xref (istream & in; vector & lt; string & gt; find_words (const string & amp;) = partition) {}  

What is the difference between two approaches? It is, a versus B:

A:

  something from zero (int (*), (player P) = myFunc) {}  
b:

  something less than nothing (intimate gratitude (player p) = myFunc) {}  

There are two different language rules involved.

One is that the function type has a parameter that, when compiling the pointer to the time in the adjusted function:

the type of each parameter After determining, to assign the "T's array" or "returning function" to any parameter of "T" or "returning indicator" respectively.

This is the rule that makes these declarations function:

  void foo (zero (* p)) ());  

and

  zero foo (zero (p) ());  

is equivalent.

The second is that the function type is an expression , in most contexts, the indicator in the contained function:

A type of function type T "Prototyme to T" can be converted into a preview, the result is an indicator for the function.

Function has been declared:

  zero function ();  

This rule is what all these calls do:

  foo (& func); Foo (function); Foo (* function); Foo (** function);  

On the last one, the expression func is the type of function, so it is converted into an indicator within the * dereferences That indicator is an expression of the function type, which is then the implicitity is then converted to an indicator and the external * works the same.

In fact, the expression foo is also converted into an indicator - which is the function-call operator (.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -