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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:18:57+00:00 2026-06-01T23:18:57+00:00

I encountered a compilation error in VS2010, and I don’t know if it should

  • 0

I encountered a compilation error in VS2010, and I don’t know if it should be considered a compiler bug or not:

I simplified the scenario as much as possible: a template class is declared a friend of some class, and tries to access the private members of the friend inside a lambda function. Here’s the code:

class Foo {
    template<typename T> friend class Bar;
    int priv;
};

template<typename T>
class Bar {
public:

    void func() {
        Foo foo;
        foo.priv = 17; // compiles
        auto lambda_func = [](Foo& _foo) { _foo.priv = 17;  }; // doesn't compile
    }
};

void test() {
    Bar<int> bar;
    bar.func();
}

Note that this only happens if Bar is a template class.

  • 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-01T23:18:59+00:00Added an answer on June 1, 2026 at 11:18 pm

    This compiles fine in g++ 4.6 and 4.7. I think it’s legal too — the lambda should have as much access as the function it is defined in.

    The C++11 standard, 5.1.2p7 says (emphasis added):

    The lambda-expression’s compound-statement yields the function-body (8.4) of the function call operator, but for purposes of name lookup (3.4), determining the type and value of this (9.3.2) and transforming id-expressions referring to non-static class members into class member access expressions using (*this) (9.3.1), the compound-statement is considered in the context of the lambda-expression.

    I read that as meaning that anything valid within the enclosing block is valid in the lambda body.

    MSVC2010 has other bugs with lambdas, so it doesn’t surprise me that it fails to compile this case.

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

Sidebar

Related Questions

I encountered some compilation errors when trying to migrate latest ffmpeg to iOS platform.
I've been installing lispbuilder-sdl family with quicklisp and encountered error in sdl-gfx: CL-USER> (ql:quickload
Following code gives compiler error which is expected ( Demo ): 1 template<bool> struct
I've recently encountered an error trying to host my asp.net site with IIS. I
Is there any possibility to make compiler continue when errors are encountered during the
Strangely I am getting compilation error in C++ for the following code. class A
I have a site running with ASP.NET MVC 1 and have encountered a bug
In case of compilation errors, ant javac task will not compile all classes which
Encountered a frustrating problem in our application today which came down to an ArrayIndexOutOfBounds
I encountered ConcurrentModificationException and by looking at it I can't see the reason why

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.