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 8234779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:35:50+00:00 2026-06-07T18:35:50+00:00

The C++11 standard says (or at least, the version I have – not the

  • 0

The C++11 standard says (or at least, the version I have – not the final one) :

The closure type for a lambda-expression with no lambda-capture has a
public non-virtual non-explicit const conversion function to pointer
to function having the same parameter and return types as the closure
type’s function call operator.

I understand why it is not possible to get a function pointer from a stateful lambda since a function pointer cannot hold any data by itself.

But when the captured objects are just a static members /static variable, there is no such limitation since the references to the captured objects can be hardwired in the function itself.

struct A {
    static int count = 0;
    void foo() {
         static int bar = 0;
         auto fun = [&]()->void {
             count++;
             bar++;
         };
         void(*ptrFun)();
         ptrFun = fun; // forbidden by the quoted wording
    }
};

Why isn’t it always possible to convert a lambda to a function pointer as soon as the former is stateless ? Am I missing something or does the committee forgot this specific point ?

  • 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-07T18:35:51+00:00Added an answer on June 7, 2026 at 6:35 pm

    A::count does not need to be captured at all. Only this and local variables need to be captured. Variables with static storage duration (e.g., static data members, namespace-scope variables, or function-local static variables) do not need to be captured because they are “unique.” There is exactly one instance of each such variable, so a reference to the object does not need to be captured.

    If you remove the default capture from your lambda (i.e., change [&] to []) and define count, it should compile without error. (I’ve verified that both Visual C++ 2012 RC and g++ 4.5.1 accept the code; the only change I had to make was to move the inline initialization of count, since neither of those compilers supports that C++11 feature yet.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a coding standard that says all shared (static) fields and methods must
The question says it all. Inter Explorer's lack of standard compliance has struck, and
I have recently discovered existence of standard fastest type, mainly int_fast32_t and int_fast64_t .
The C++ standard says (8.5/5): To default-initialize an object of type T means: If
I'm trying to understand the C++11 concepts. The standard draft which I have says:
Anyone have a link to what the C++ standard says regarding a compiler removing
The standard says that dereferencing the null pointer leads to undefined behaviour. But what
I know that the C++ standard says that return 0 is inserted at the
Within the same compilation unit, the C++ standard says that static initialization order is
The MPI standard (page 295) says: Advice to users. Whether the errorcode is returned

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.