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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:54:24+00:00 2026-05-24T02:54:24+00:00

From the wikipedia article about Lambda functions and expressions : users will often wish

  • 0

From the wikipedia article about Lambda functions and expressions:

users will often wish to define predicate functions near the place
where they make the algorithm function call. The language has only one
mechanism for this: the ability to define a class inside of a
function. … classes defined in functions do not permit them to be used in templates

Does this mean that use of nested structure inside function is silently deprecated after C++0x lambda are in place ?

Additionally, what is the meaning of last line in above paragraph ? I know that nested classes cannot be template; but that line doesn’t mean that.

  • 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-05-24T02:54:24+00:00Added an answer on May 24, 2026 at 2:54 am

    Is there any use case for class inside function after introduction of lambda ?

    Definitely. Having a class inside a function is about:

    • localising it as a private implementation detail of the code intending to use it,
    • preventing other code using and becoming dependent on it,
    • being independent of the outer namespace.

    Obviously there’s a threshold where having a large class inside a function harms readability and obfuscates the flow of the function itself – for most developers and situations, that threshold is very low. With a large class, even though only one function is intended to use it, it may be cleaner to put both into a separate source file. But, it’s all just tuning to taste.

    You can think of this as the inverse of having private functions in a class: in that situation, the outer API is the class’s public interface, with the function kept private. In this situation, the function is using a class as a private implementation detail, and the latter is also kept private. C++ is a multi-paradigm language, and appropriately gives such flexibility in modelling the hierarchy of program organisation and API exposure.

    Examples:

    • a function deals with some external data (think file, network, shared memory…) and wishes to use a class to represent the binary data layout during I/O; it may decide to make that class local if it only has a few fields and is of no use to other functions
    • a function wants to group a few items and allocate an array of them in support of the internal calculations it does to derive its return value; it may create a simple struct to wrap them up.
    • a class is given a nasty bitwise enum, or perhaps wants to reinterpret a float or double for access to the mantisa/exponent/sign, and decides internally to model the value using a struct with suitable-width bitfields for convenience (note: implementation defined behaviours)

    classes defined in functions do not permit them to be used in templates

    I think you commented that someone else’s answer had explained this, but anyway…

    void f()
    {
        struct X { };
        std::vector<X> xs;  // NOPE, X is local
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is the statement written from Wikipedia's Isolation article about REPEATABLE READS In this
From the Wikipedia article on Read-Copy-Update : The reason that it is safe to
From this Wikipedia article: http://en.wikipedia.org/wiki/Hamiltonian_path_problem A randomized algorithm for Hamiltonian path that is fast
From a quick Google search and a the wikipedia article on Multiple Inheritance, which
What would be the easiest way to get all articles about people from Wikipedia?
I read the Wikipedia article about the curiously recurring template pattern in C++ for
I'm talking mostly about functional programming languages. For example, the wikipedia article for map
From Wikipedia : Generic programming is a style of computer programming in which algorithms
From Wikipedia, the free encyclopedia: Closure (computer science) In computer science, a closure is
From wikipedia: the cross product is a binary operation on two vectors in a

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.