Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8702591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:41:25+00:00 2026-06-13T02:41:25+00:00

Is there a way, when writing a lambda function within a member function, to

  • 0

Is there a way, when writing a lambda function within a member function, to capture fields of the enclosing class by value? The default catch-all = doesn’t work because when I reference the variable inside the lambda I get instead a dereferencing from the captured this pointer, as well as explicitly naming the variable in the capture list, because I get two compile error: capture of non-variable <name>, and ‘this’ was not captured for this lambda function

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:41:26+00:00Added an answer on June 13, 2026 at 2:41 am

    No, data members cannot be captured by value. A lambda can capture only two kinds of things:

    1. the this pointer, and
    2. nonstatic local variables (that is, variables with automatic storage duration).

    As has been noted by ildjarn in the comments, you can create a local variable with a copy of the value of the data member, and capture that local variable by value.

    I would argue that if explicit by-value capture of a data member was allowed, it could prove confusing, since the behavior of explicit capture would differ from that of implicit capture. For example, given an accessible data member of type int named m, it would be odd that the following would produce different results:

    [=] () mutable { m = 1; } // we modify this->m
    [=m]() mutable { m = 1; } // we modify the copy of m that was captured
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if there is a way of writing a method or a class
There has to be a better way of writing the js in my function....
Is there a better way of writing this? $('<span class=a></span>').insertAfter($('#email')); $('<span class=a></span>').insertAfter($('#username')); $('<span class=a></span>').insertAfter($('#password'));
Is there a better way of writing this code: http://jsfiddle.net/2u7fg/2/ $('img').filter(function() { return $(this).attr('align').length
Is there a way of writing an XPath expression to select the content of
Is there a way to avoid writing std::vector<int> twice on lines such as these?
Is there a better way of writing the following for loop? my_list = []
Is there a better way of writing the following method? Using LINQ maybe? Instead
Is there a platform-independent way of writing the EOF symbol to a string in
I am writing WCF service hosted in WinForms application. Is there some way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.