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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:08:47+00:00 2026-05-31T13:08:47+00:00

Why the compiler gives me an error when I don’t initialize a value to

  • 0
  1. Why the compiler gives me an error when I don’t initialize a value to a static member variable? Shouldn’t it be initialized to 0?
  2. Why I have to initialize member variable outside the class? (is this illegal because if you do so, and change the value of this static member variable inside the main function and you create an object of this clas, it will re-assign the static mamber variable to the old value) whereas const static member variable are legal to be initilized inside the class (and this is possible because you can’t change the value of this static member variable anyway)?

Error: undefined reference to class_name::a

  • 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-31T13:08:47+00:00Added an answer on May 31, 2026 at 1:08 pm

    From the error posted, the linker is stating that the variable has not been defined, not that it has not been explicitly initialised:

    class A
    {
        // declaration.
        static int x;
    };
    
    // definition (in this case without explicit initialisation).
    int A::x;
    

    The linker should not emit an error and the compiler should not emit a warning, as long as no attempt is made to use the static variable before it has been assigned an initial value.

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

Sidebar

Related Questions

g++ compiler gives this error: expected `;' before 'it' template <typename T> class myList
In C++ the following code gives a compiler error: void destruct1 (int * item)
I have a class in C# with a template and static method similar to
I have a class named Particle which has a std::set as a member. The
The following gives an Internal Compiler Error on MSVC++ 10 Sp1. And on gcc:
I'm trying to use g_rename and compiler gives me strange message error: called object
Is there a standard/common way to give compiler-style error messages that point to a
The compiler doesn't give me any error and the code runs. Just curious how
Upcasting is allowed in Java, however downcasting gives a compile error. The compile error
when I'm trying to compile my c program it gives me this error warning:

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.