c++ - c++11 what is the scope for the lambda function below -


If it does not capture if it does not capture, as a result, given the example given below this water, what should I expect from the life time of this function available for callback? The lambda function is defined on which scope? Local area, package area, global scope? In this case, there is a problem calling the Lambda after the function is out? I am not using std :: function here, so please do not respond to the solution with the std :: function return value. My question is to really understand the scope of that function (without confinement) and if it is available for the lifetime of the program.

  #include & lt; Iostream & gt; Typef int (* FPTT) (int, int); fPtrT fx () {return static_cast & lt; FPtrT & gt; ([] (Int i, int j) {return i + j;}); } Int main () {std :: cout & lt; & Lt; Fx (5,2)  & Lt; Std :: endl; } A lambda expression gives an example of an anonymously defined class (type).  

Is known only for the compiler). Overloads the operator () to serve this class.

On top of that, lambda quote which does not close any state, has been converted into a C-style function pointer. In those cases, imagine that the operator () simply invokes a constant function (and the underlying conversion is an indicator on that static function).

By knowing all this, we

  • whenever the fx function is applied, an example of an anonymous class is created
      < Li> This example is an R-value; As it exists only by the end of the statement
    • fx function by returning the function indicator is an indicator for a static function is effective. >
    • The function pointer can be used safely by any person (because it is not a shared status)

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -