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 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

I understand that a class that consists of nothing but public static member functions
There were many questions about C++ template classes which contain static member variables, as
I can declare private static member variables in a class, but what does it
how to initialize a private static member of a class in java. trying the
I have a class which have a static member. As I understand, all static
I want to forward declare a static member function of a class in another
I am parallelizing calls to newSeed() and rand(),static member functions of class Random. newSeed()
I have this class that has a static member. it is also a base
I have written a class (AbcdBase) which holds several static objects, these include maps
I have a problem regarding 'static const' member initialization. In a templated class I

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.