Practical use case of Static | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

21st Mar 2022, 1:03 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
6 Answers
+ 1
coroutines
21st Mar 2022, 2:14 PM
Raul Ramirez
Raul Ramirez - avatar
+ 1
Ketan Lalcheta In this article youll find and explanation and implementation of coroutines https://www.geeksforgeeks.org/coroutines-in-c-cpp/
22nd Mar 2022, 1:49 PM
Raul Ramirez
Raul Ramirez - avatar
0
Raul Ramirez thanks but I am not much aware about coroutines much and hence will explore and then try to corelate
22nd Mar 2022, 5:58 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
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...
22nd Mar 2022, 5:59 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
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
22nd Mar 2022, 10:04 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Thanks Guys. One more use case I come across is to encapsulate data for a specific translation unit in c
24th Mar 2022, 11:13 AM
Ketan Lalcheta
Ketan Lalcheta - avatar