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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:56:51+00:00 2026-05-26T21:56:51+00:00

What is the reasoning to why static const members cannot exist in local classes?

  • 0

What is the reasoning to why static const members cannot exist in local classes? It seems like a rather silly restriction.

Example:

void foo() {
  struct bar {
    int baz() { return 0; }   // allowed
    static const int qux = 0; // not allowed?!?
  };
}

struct non_local_bar {
  int baz() { return 0; }   // allowed
  static const int qux = 0; // allowed
};

Quote from standard (9.8.4):

A local class shall not have static data members.

  • 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-26T21:56:52+00:00Added an answer on May 26, 2026 at 9:56 pm

    From the standard section 9.4.2:

    If a static data member is of const integral or const enumeration
    type, its declaration in the class definition can specify a
    constant-initializer which shall be an integral constant expression.
    In that case, the member can appear in integral constant expressions
    within its scope. The member shall still be defined in a namespace
    scope
    if it is used in the program and the namespace scope definition
    shall not contain an initializer.

    Basically, local classes have no linkage, and static data members require a linkage.

    Since there’s no way to define a static data member of a local class in namespace scope (a declaration with an initializer is not a definition), they are not allowed, whether they are of const integral type or not. On the surface it may seem like the compiler should just be able to inline the value, but then what happens if you try to access a pointer to the member? With namespace scoped classes you’d just get a linker error, but local classes have no linkage.

    I guess in theory they could just allow you to use static const integral types in local classes as long as they are only used in integral constant expressions, but it would probably just put too much of a burden on the standards body and compiler vendors to differentiate for very little practical value; local static variables are accessible from local classes, so using a local static const should be just as good.

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

Sidebar

Related Questions

Here's an example of a utility method: public static Long getFileSize(String fileString) { File
Sometimes I'd like to know the reasoning of certain API changes. Since Google hasn't
I stumbled upon this code: static void Main() { typeof(string).GetField(Empty).SetValue(null, evil);//from DailyWTF Console.WriteLine(String.Empty);//check //how
When I try to compile the following: public static delegate void MoveDelegate (Actor sender,
I would like to know what the reasoning could be for inconsistent way sql
Summary Can you explain the reasoning behind the syntax for encapsulated anonymous functions in
What was (or would be) the reasoning behind creating TDataSource as an intermediary between
I have a set of classes which extend an abstract class. The abstract class
EDIT The original reasoning for this question was a pretty serious case of bad
I've always wondered the reasoning behind why we must always define D3DVERTEX . Is

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.