adspace


Explain the static member function.

Answer Posted / Dwijendra Kumar Upadhyay

A static member function in C++ is a non-static member function that can only access other static members of its class and has no this pointer. It belongs to the class, not the object. Static functions are used when we want to share data among all objects of the same class rather than each object having its own copy.nnExample:n```cppnclass Counter {nprivate:n static int count;npublic:n Counter() { count++; }nstatic void displayCount() { cout << "Total objects: " << count << endl; }n};nint Counter::count = 0;nint main() {n Counter c1, c2, c3;n Counter::displayCount();n return 0;n}n```

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

daily Routine of father

1484


What character terminates all character array strings a) b) . c) END

1394


Can union be self referenced?

1266


What is the latest version on c++?

1206


How c functions prevents rework and therefore saves the programers time as wel as length of the code ?

1164