Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is meaning of "[=]" in cpp

Tags:

c++

c++11

lambda

Please check this code below:

NodeScheduleLambda(this, 0.01f, [=]
{
    this->removeFromParentAndCleanup(true);
});

In that what is the meaning of "[=]" this. Can any one help me.Thank you...

like image 841
Sudhakar Avatar asked Jan 04 '23 01:01

Sudhakar


1 Answers

A lambda is an unnamed/anonymous function that is useful in programming due to it's short snippets of code.

lambda function in C++ defined like this

[]() { }

[] is the capture list, () the argument list and {} the function body.

The capture list defines what from the outside of the lambda should be available inside the function body and how. It can be either:

  • a value: [x]
  • a reference [&x]
  • any variable currently in scope by reference [&]
  • same as third type, but by value [=]

You're passing a lamda function as third argument using fourth capture list.

NodeScheduleLambda(this, 0.01f, [=]{ this->removeFromParentAndCleanup(true); });
like image 90
Abhishek Aryan Avatar answered Jan 09 '23 18:01

Abhishek Aryan