Practical use case of Static | Sololearn: Learn to code for FREE!

+3

Practical use case of Static

Hi We do have static member variable and static member functions. I am aware that static member variables will not have multiple copies due to object and it will be only one class level allocation. Static member functions can only access the static members. Practical use of static function and variable is singleton design pattern as well as how many objects got created of some type. What else in terms of real example for static?

3/21/2022 1:03:43 PM

Ketan Lalcheta

9 Answers

New Answer

+1

coroutines

+1

Ketan Lalcheta In this article youll find and explanation and implementation of coroutines https://www.geeksforgeeks.org/coroutines-in-c-cpp/

0

Raul Ramirez thanks but I am not much aware about coroutines much and hence will explore and then try to corelate

0

Manav Roy[LESS ACTIVE DUE TO EXAMS] thanks.... But isn't it a good idea to use some other data structure to store objects of class student... This class can have only name as member variable and no need of static array...

0

Thanks but I would like to disagree on this use case. I am not saying that it's not correct or it's not good to do so... My main thing is that I am not comfortable with this use case of static . I might be wrong here also. Any other use case if you would like to share ? And once again thanks for your time, effort and help

0

Thanks Guys. One more use case I come across is to encapsulate data for a specific translation unit in c