Explain the static member function.



Explain the static member function...

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

More C++ General Interview Questions

What is flag in computer?

1 Answers  


Distinguish between a # include and #define.

1 Answers  


What is the basic difference between C and C++?

1 Answers   NIIT,


If a round rectangle has straight edges and rounded corners, your roundrect class inherits both from rectangle and from circle, and they in turn both inherit from shape, how many shapes are created when you create a roundrect?

1 Answers  


Write a program using GUI concept for the scheduling algorithms in Operating system like SJF,FCFS etc..

1 Answers  


Which coding certification is best?

1 Answers  


What is a container class?

1 Answers  


How a pointer differs from a reference?

1 Answers  


Is it possible to get the source code back from binary file?

2 Answers  


What is meaning of in c++?

1 Answers  


how many controls can we place on single form.

1 Answers   Microsoft,


What is Object Oriented programming.what is the difference between C++ and C?

8 Answers   Infosys,


Categories