+ Reply to Thread
Results 1 to 2 of 2

Thread: Modifying variable inside a lambda that is declared outside lambda

  1. #1

    Modifying variable inside a lambda that is declared outside lambda

    I am having some issue that whether I can modify the variable that is declared outside the lamda or not. Is it possible? If yes how to do this? Please help.

  2. #2
    Below is simple example of how to do this:

    Code:
    void ModifyVaalue()
    {
    	int a1 = 10 ;
    	auto fun = [&a1] ()
    					{
    						a1 = 20 ;
    					} ;
    
    	fun() ;
    
    	int a2 = a1 ; //a1 is now 20!
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts