Skip to main content

Static Data Member

 A data member of a class can be qualified as statics. The properties of a static member variable are similar to that of a C static variable. A static member variable has certain special characteristics. These are:

  • It is initialized to zero when the first object of its class is created. No other initialization is permitted.
  • Only one copy of that member is created for the entire class and is shared by all the objectives of that class, no matter how many objects are created.
  • It is visible only within the class, but its lifetime is the entire program.

#include <iostream>

using namespace std;

class item
{
       static int count;
       int number;
       public:
       void getdata(int a)
       {
           number=a;
           count ++;
       }
       void getcount(void)
       {
           cout<< "count";
           cout<< count <<"\n";
       }
};
int item::count;
int main()
{
        item a,b,c;
        a.getcount();
        b.getcount();
        c.getcount();
        
        a.getdata(100);
        b.getdata(200);
        c.getdata(300);
        
        cout<<"After reading data" << "\n";
        
        a.getcount();
        b.getcount();
        c.getcount();
        return 0;
}


Comments

Popular posts from this blog

How to Install Parrot Operating System in Virtual Box using OVA

Step by Step Process of Parrot OS Installation What is Parrot OS Parrot is a free and open-source Linux system based on Debian that is popular among security researchers, security experts, developers, and privacy-conscious users. It comes with cyber security and digital forensics arsenal that is totally portable. It also includes everything you'll need to make your own apps and protect your online privacy. Parrot is offered in Home and Security Editions, as well as a virtual machine and a Docker image, featuring the KDE and Mate desktop environments. Features of Parrot OS The following are some of the features of Parrot OS that set it apart from other Debian distributions: Tor, Tor chat, I2P, Anonsurf, and Zulu Crypt, which are popular among developers, security researchers, and privacy-conscious individuals, are included as pre-installed development, forensics, and anonymity applications. It has a separate "Forensics Mode" that does not mount any of the system's hard...

Static Member Functions

  What is static member functions? A static member function can access static data members and static member functions inside or outside of the class. Static member functions have a scope inside the class and cannot access the current object pointer. You can also use a static member function to determine how many objects of the class have been created. Static Member Function in a class is the function that is declared as static because of which function attains certain properties as defined below: A static member function is independent of any object of the class.  A static member function can be called even if no objects of the class exist. A static member function can also be accessed using the class name through the scope resolution operator. A static member function can access static data members and static member functions inside or outside of the class. Static member functions have a scope inside the class and cannot access the current object pointer. You can also u...

Hadoop file Management Tasks

  Implement the following file management tasks in Hadoop: a) Adding files and directories b) Retrieving files c) Deleting files Hint: A typical Hadoop workflow creates data files (such as log files) elsewhere and copies them into HDFS using one of the above command line utilities. Program:  The most common file management tasks in Hadoop includes: Adding files and directories to HDFS Retrieving files from HDFS to local filesystem Deleting files from HDFS Hadoop file commands take the following form:     hadoop fs - cmd Where cmd is the specific file command and <args> is a variable number of arguments. The command cmd is usually named after the corresponding Unix equivalent. For example, the command for listing files is ls as in Unix. a) Adding Files and Directories to HDFS Creating Directory in HDFS    $ hadoop fs - mkdir foldername (syntax)  $ ha...