Interview Questions   Tutorials   Discussions   Programs   Videos   

C++ - Why static Function is used in C++?

asked marvit August 18, 2014 10:49 AM  

Why static Function is used in C++?


1 Answers

answered By bhjahnavi   0  

Assuming that you're using oop, use static functions when they don't depend on any class members. They can still be private, but this way they are optimized as they don't depend on any instance of the related object.

Other than the above, I find static functions useful when you don't want to create an instance of an object just to execute one public function on it. This is mainly the case for helper classes that contain public functions to do some repetitive and general work, but don't need to maintain any state between calls.

   add comment

Your answer

Join with account you already have



Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!