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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:52:46+00:00 2026-05-13T23:52:46+00:00

Could any body offer me any reason about that? If we do it like

  • 0

Could any body offer me any reason about that?

If we do it like that, what’s the outcome? Compile error?

  • 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-13T23:52:46+00:00Added an answer on May 13, 2026 at 11:52 pm

    The problem is that static initialization isn’t just initialization, it is also definition. Take for example:

    hacks.h :

    class Foo
    {
    public:
        static std::string bar_;
    };
    
    std::string Foo::bar_ = "Hello";
    
    std::string GimmeFoo();
    

    main.cpp :

    #include <string>
    #include <sstream>
    #include <iostream>
    
    #include "hacks.h"
    
    using std::string;
    using std::ostringstream;
    using std::cout;
    
    int main()
    {
        
        string s = GimmeFoo();
        return 0;
    }
    

    foo.cpp :

    #include <string>
    #include <sstream>
    #include <iostream>
    
    #include "hacks.h"
    
    using std::string;
    using std::ostringstream;
    using std::cout;
    
    string GimmeFoo()
    {
        Foo foo;
        foo;
        string s = foo.bar_;
    
        return s;
    }
    

    In this case, you can’t initialize Foo::bar_ in the header because it will be allocated in every file that #includes hacks.h. So there will be 2 instances of Foo.bar_ in memory – one in main.cpp, and one in foo.cpp.

    The solution is to allocate & initialize in just one place:

    foo.cpp :

    ...
    std::string Foo::bar_ = "Hello";
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could any body kindly advise me about the app.config file. When application is complied,
could any body tell how to use Jquery calendar date time picker.
Could any body diagnose the problem I am facing? As you run the demo
Could any body clarify these two expression for me ? What are cons and
I am new to ASP.net mvc could any body help me out how to
Could any body explain, when to use TempData ViewBag ViewData I have a requirement,
Could any body give a short example for binding a value from list array
could any body explain what I should modify, how after hiding the image, still
Could any body simply tell me what Medium Trust level is ? And what
Could anybody brief about user_token functionality in Auth module? What is a use and

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.