Static Member Function Example in C++


By declaring a function member as static, you make it independent of any particular object of the class. A static member function can be called even if no objects of the class exist and the static functions are accessed using only the class name and the scope resolution operator ::.

Example Program:

Here is the simple program static member function in C++.

Source Code

//Static Member Variable
using namespace std;

class Test

private :
    int a,b;
    static int count;
    static int getCount()  //Static Member function returns only static variables
        return count;
int Test::count=0;
int main()
    Test t1;
    cout<<"T1 :"<<Test::getCount();

To download raw file Click Here


T1 :1

Program List

Flow Control

IF Statement Examples

Switch Case

Goto Statement

Break and Continue

While Loop

Do While Loop

For Loop

Friend Function in C++

String Examples

Array Examples

Structure Examples

Structure & Pointer Examples

Structure & Functions Examples

Enumeration Examples

Template Examples


Inheritance Examples

Hierarchical Inheritance

Hybrid Inheritance

Multilevel Inheritance

Multiple Inheritance

Single Level Inheritance

Class and Objects

Constructor Example

Destructor Example

Operator Overloading Example

Operator and Function Example

List of Programs

Pointer Examples

Memory Management Examples

Pointers and Arrays

Virtual Function Examples

Learn All in Tamil © Designed & Developed By Tutor Joes