What is a static function? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

What is a static function?

23rd Jul 2016, 12:36 PM
Aceitunarabe
Aceitunarabe - avatar
3 Respostas
+ 1
Okey I see, moreover it can be used with an array e.g. static const char arrayOfChar [] Here what is the meaning?
23rd Jul 2016, 12:53 PM
Aceitunarabe
Aceitunarabe - avatar
0
A static function is a function that only must be known in the translation unit it is defined in, i.e. the cpp. Therefore, if you compile a file with definitions (e.g. a header file) multiple times for a build artifact, the "one definition rule" (ODR) is not violated. ODR was introduced in C++03 to remove ambiguity when linking multiple binary files that contain functions with the same name but might have different implementations.
23rd Jul 2016, 12:46 PM
Stefan
Stefan - avatar
0
A static function *in a class* on the other hand is a function that does not require an object instance of the class to be called. Unfortunately, as you see, what the static keyword does pretty much depends on the context in which it is used.
23rd Jul 2016, 12:48 PM
Stefan
Stefan - avatar