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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:09:02+00:00 2026-05-17T00:09:02+00:00

I have heard that using static member objects is not a very good practice.

  • 0

I have heard that using static member objects is not a very good practice.

Say for example, I have this code:

class Foo {
...
static MyString str;
};

I define and initialize this variable in the implementation file of this class as:

MyString Foo::str = "Some String"; // This is fine as my string API handles this.

When I run this code, I get a warning:

warning:'Foo::str' requires global construction.

I have quite much of such members in my class, what is the best way to handle this.

Thanks,

  • 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-17T00:09:03+00:00Added an answer on May 17, 2026 at 12:09 am

    Most of the arguments against them are the same as for global variables:

    1. Initialization order between different compilation units is undefined.
    2. Initialization order inside one compilation unit may affect the behavior — thus non trivial ordering may be required.
    3. If a constructor throws an exception you can’t catch it, your program is terminated.

    APPENDED: To handle this properly you must either make sure that above points don’t apply to your code and ignore the warning, or redesign your program: Do you really need them static? Why not use const char* Foo::str = "Some String";?

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

Sidebar

Related Questions

I have often heard that using break s in Java is considered bad practice,
I have heard that in C++, using an accessor ( get...() ) in a
I'm considering using JRuby on App Engine but have heard that Juby app on
I have an NSIS installer that has the start menu folders hard-coded using this
I have heard that GTK covers all controls so that developers do not care
I have heard that DateTime.Now is very expensive call (from here ) Is GETDATE()
I have a structure that can be very easily represented using a three-deep nested
this is my first interaction with this site, I have heard good things and
I've heard that using exceptions for control flow is bad practice. What do you
I have heard that when dealing with mutexes, the necessary memory barriers are handled

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.