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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:25:42+00:00 2026-06-16T04:25:42+00:00

I was of the impression that C++ applies the same special rules to a

  • 0

I was of the impression that C++ applies the same special rules to a static const integral type regardless of whether declared at namespace scope or declared within a class/struct/union.

Now I’m thinking that I’ve been taught Bad Things by non-compliant compilers.

static const int A = 1;

struct s
{
    static const int A = 1;
};

Aside from the obvious difference in scope, How do A and s::A differ?

  • …when their usage will be replaced with their literal value?
  • …when I can take the address of it?
  • …when I need to separately define them?

I’m curious specifically about C++ 03.

  • 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-16T04:25:43+00:00Added an answer on June 16, 2026 at 4:25 am

    The keyword static doesn’t mean the same thing in class scope
    and in namespace scope. In fact, it’s use in namespace scope is
    deprecated.

    When declaring a variable at class scope, static means that
    there will be one single instance of the variable, with static
    storage duration and lifetime. The declaration within the class
    is not a definition; if the variable is used, it must be
    defined in one (and only one) translation units; if it is not
    defined, you have undefined behavior. (In practice, depending
    on the use, either everything will work fine, or you will get an
    error from the linker.) Note that if the declaration is for
    a const integral type, and contains an initialization, it is
    not considered used if it is used in a context which requires
    a constant integral expression (like the dimension of a C style
    array). The simplest and surest thing is just to define it
    somewhere.

    When declaring a variable at namespace scope, static means
    that the name has internal linkage, rather than external; with
    or without static, the declaration is a definition (so there
    should be no other definition in the program). In C++03, this
    use was deprecated; use unnamed namespace instead. Note too
    that if the variable itself is const (top level const), then
    it has internal linkage by default, so the static has no
    effect whatsoever. (If you need a const variable with
    external linkage, make it a class member, or define it
    explicitly extern, using an initializer to make it
    a definition, rather than just a declaration.)

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

Sidebar

Related Questions

I was under the impression that the css rules in the callback function below
I had the impression that Class.forName(String className) used the Thread.currentThread().getContextClassLoader() to load the class
I was under the impression that when we send mail to any domain (i.e.
I'm under the impression that a control in a nested UpdatePanel will cause the
I was under the impression that when you called Flush() in a StreamWriter object
I was under the impression that I could get the value of a select
I was under an impression that the left hand side of the colon :
It's my impression that schemas are mainly for organizing the tables, view, stored procedures,
I was under the impression that using the Resolve method returned a new instance
I was under the impression that I could put any old executable program in

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.