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

  • Home
  • SEARCH
  • 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 8219131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:03:12+00:00 2026-06-07T13:03:12+00:00

A .cpp file has a bunch of class definitions . One class has a

  • 0

A .cpp file has a bunch of class definitions . One class has a private static member as follows:

class SomeClass:public SomeParentClass
{
   private:
     static int count;
};

and right after the class is defined, the count attribute to initialized to zero as follows:

int SomeClass::count = 0;

Coming from the Java/C# world I am having trouble understanding at which point is count initialized to zero? Is it when the SomeClass is instantiated? Also, the class definition has the count type to be int, why does the SomeClass::count has to have an int in front of it?

And my last question is, since the count attribute is private shouldn’t its visibility be restricted when it is initialized outside the class definition?

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-06-07T13:03:14+00:00Added an answer on June 7, 2026 at 1:03 pm
    1. Static members of the class are initialized in arbitrary order upon your program’s start-up
    2. The static int count; in the class is a declaration of your static variable, while int SomeClass::count = 0; is its definition. All definitions in C++ require to specify a type.
    3. The fact that the definition of the count appears to have occurred in the file scope, the actual scope of the SomeClass::count remains private, as declared.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

header file: private: vector<int*>* nums; public slots: void buttonClicked(); cpp file: NewWindow(){ int one
I've got an application that's using a static library I made. One .cpp file
Static variable has file scope. Say I have two following files: file1.h file1.cpp file2.h
I have one class, called A, and it has it's own header file. Then
In my A.h file: class A{ private: unsigned short PC; public: A():PC(0){} virtual ~A(){}
I have a .cpp file which has some static free functions. I know how
Suppose one has about 50,000 different .cpp files. Each .cpp file contains just one
I have three files, a main .cpp file: #include <stdio.h> #include myClass.h int main()
I want to use some functions from a .cpp source file that has a
I have the following code in my header file: class Factovisors { public: Factovisors(std::istream&

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.