The member functions are two types:

  • static member functions
  • non-static member functions

The static member functions don’t have the ‘this’ pointer and static member functions can access only static data members whereas non-static member functions can access both static and non-static data members.

Simple Program for Static Members Functions Using C++ Programming program

#include<iostream>
using namespace std;
class Demo_Static{ 
static int count;
public: Demo_Static(){ 
count++; } 
static int getCount(){ 
return count;
} }; 
int Demo_Static :: count;
int main(){ 
Demo_Static s1,s2,s3;
cout<<"The value of a is :"<<Demo_Static::getCount();
return 0; 
}

Output:-The value of a is :3

Explanation of the program

In this program, the count is declared as a static variable. This variable is accessed by all objects and the value of count is the same when each object accesses it since only one copy of it is created and maintained.

This article is written by our awesome writer
Comments to: Static Member Functions in C++ with Example

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Latest Articles

Explore Tutorials By Categories

About

Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page

Login

Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
  •  
    Strength indicator
  •  
  •  
    Log In | Lost Password