0
What is the use of static functions and static member functions.
2 Answers
+ 1
if you have a class with a static function that function can be called without ever creating an instance of said class. like so: class::func(). A static member function will only be able to access static member variables. You could for example have a timer class that returns the time the Programm has run when calling Timer::getRuntime ().
But how is this usefull?
Imagine you have your Programm split in 20 .cpp and .h files. whenever you complete a tasks in one of your files you might want to log the time using our timer class. if you function is static all you will have to do is include your timer.h file and call Timer::getTime ().
Otherwise you would have to create a Timer object (or get it somehow) in each of your other classes and store it (or get a fresh one everytime).
+ 1
still I'm not getting cleared with the topic, can you share some source for this.