Static functions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 19

Static functions

Can somebody explane static functions in c++

22nd Nov 2016, 8:10 AM
Lara
Lara - avatar
2 Answers
+ 6
In C++, "static" applies to member functions and data members of classes. A static data member is also called a "class variable", while a non-static data member is an "instance variable". This is Smalltalk terminology. This means that there is only one copy of a static data member shared by all objects of a class, while each object has its own copy of a non-static data member. So a static data member is essentially a global variable, that is a member of a class. Non-static member functions can access all data members of the class: static and non-static. Static member functions can only operate on the static data members. One way to think about this is that in C++ static data members and static member functions do not belong to any object, but to the entire class. That means for all object of a class there is a same static function and variable. what Object Orientation terms a static method. Lives inside a class. You call this with the class rather than through an object instance.
22nd Nov 2016, 12:23 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 3
static functions at the file scope are local to that file, and not visible outside this file.
22nd Nov 2016, 8:12 AM
Udi Finkelstein
Udi Finkelstein - avatar