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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:43:26+00:00 2026-05-21T15:43:26+00:00

What are disadvantages of using static variables like in following code: namespace XXX {

  • 0

What are disadvantages of using static variables like in following code:

namespace XXX
{
    static int i;
    class YYY
    {
        static m_i;     
    };
}

Is using static variables only in .cpp (so they are invisible to other code) file OK?

  • 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-21T15:43:27+00:00Added an answer on May 21, 2026 at 3:43 pm

    Various things allowed by C++ represent choices and compromises in software design. There is nothing inherently, absolutely evil about any of them (except perhaps throw specifications, which Prof. Stroustrop deems a broken facility ;-P).

    Whether this particular code is a good choice in a particular situation depends on many factors. For example:

    • there’ll only be one copy shared by the entire program
      • may be ideal, e.g. you want to have some program-wide modal state
      • terrible: code setting/using the value may find other code has modified it meanwhile (this gets increasingly likely as the program gets larger and more complex)
      • terrible: in multi-threaded code you must use locking and/or atomic operations to avoid data corruption and consequent erroneous behaviour and/or crashes
    • being static:
      • other translation units won’t have access to it
      • it won’t pollute the symbol table exposed by a good IDE etc.

    In short, if you realise that namespaces and static just reduce identifier clashes, they’ve got all the other pros/cons associated with global variables….

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

Sidebar

Related Questions

Would like to get a list of advantages and disadvantages of using Stored Procedures.
Say I have two classes like this: class A{ private static Random random =
consider the following two pieces of code: public static Time Parse(string value) { string
Possible Duplicate: Static members class vs. normal c-like interface I am looking at somebodies
What are the advantages and disadvantages of using header files in a language like
Are there any disadvantages to using word-wrap:break-word in the following way? body { word-wrap:
What advantages and disadvantages using nginx+Apache+mod_wsgi vs nginx+uWSGI(vurtualenv) in production Advantages of first variant
What is the advantages/disadvantages of using inline functions in C++? I see that it
Please give me the advantages and disadvantages of using the particular framework. Can give
What are the advantages and disadvantages of using one instead of the other 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.