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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:22:03+00:00 2026-05-18T23:22:03+00:00

//static member in classes #include <iostream> using namespace std; class CDummy { public: static

  • 0
    //static member in classes
#include <iostream>
using namespace std;

class CDummy {
public:
    static int n;
    CDummy() {n++;};
    ~CDummy(){n--;};
};

int CDummy::n =0;

int main(){
    CDummy a;
    CDummy b[5];
    CDummy *c = new CDummy;
    cout << a.n << endl;
    delete c;
    cout << CDummy::n << endl;
    return 0;
}

The result is 7, 6.
Can anybody explain it for me?
and I don’t understand this “CDummy b[5];”. People never use syntax like this in C, right? what is this here?
Thank you!

  • 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-18T23:22:03+00:00Added an answer on May 18, 2026 at 11:22 pm
    CDummy b[5];
    

    This declares an array of five CDummy objects. It ends up calling the CDummy default constructor five times (once for each object in the array).

    You create seven CDummy objects: a, five in the array b, and the one pointed to by c. n then has a value of 7. Then you destroy one CDummy object (the one pointed to by c) and n has a value of 6. The remaining six CDummy objects are destroyed when they go out of scope when the main function returns.

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

Sidebar

Related Questions

How can I access a public static member of a Java class from ColdFusion?
If you have a class member that is static and public . Would you
I have a base class that has a private static member: class Base {
All the member variables and member functions in my class ClassA are static. If
I have this class that has a static member. it is also a base
I have a problem regarding 'static const' member initialization. In a templated class I
I am trying to access static member of a class. my class is: class
I'm trying to write a static member function in C# or find one in
Is there anyway to have a sort of virtual static member in C++? For
I would like to know what is the difference between initializing a static member

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.