alright so i understand how a static variable works..but i dont understand how a static function works..i cant find any clear info on it..does anyone have a nice smart way of explaining it? :)
thanks
Printable View
alright so i understand how a static variable works..but i dont understand how a static function works..i cant find any clear info on it..does anyone have a nice smart way of explaining it? :)
thanks
static functions like static variables have class scope but are independent of objects, so declaring a function static within a class disables its access to the object variables, which is of course good if you don't need them (as it doesn't need an object and you call the function with classname::functionname).
Or.
Volatile functions are 'created' on the fly. The arguments are pushed on the stack, the function's variables are initialized, the function is executed, return values are pushed onto the stack and all of the functions variables are destroyed, along with any associated stack space. Memory efficient.
If a function calls another function, then all variables, the local stack & stack pointers, register contents are all pushed onto the stack, then destroyed. This invokes execessive stack use for nested functions that are called from different places.
Static functions are never dereferenced (destroyed). Neither are the variables. Static functions hold onto more memory at the start, but depending on what the program is doing, may be faster.
But, if you have multiple entry points into the static function you can introduce bugs.
Aren't you refering to static local variables jim? if not then thats something i didn't know.
Yep, jim's confusing things here.
Anyway, if it's not within class scope, a static function is simply only available withing the source file it is defined in.