what is the output If there is one class template which has one static member variable ?
static vairaible in class templates
Collapse
X
-
Tags: None
-
i mean can we add a static vairaible in a class template, if we can add what is the possibility:Originally posted by MACKTEKcan you be more specific, maybe add an example.
a)Every instance of class template will share the same copy of static variable
b) Every instance of class template will have its own copy of static variable.
c)or it will give any compiler error.Comment
-
You can declare static variables either locally or globally.
Local static variables are specific to the class or function or block of code.
The nice thing is that no matter how many time you call that piece of code, the SAME variable value is there. The compiler knows not to initialize a static variable more than 1 time.
So, yes every instance of a class that has a local static variable will have access to the SAME static variable. Thus changing it in 1 instance will change it in all other instances.
Global static variables are similar to local except they apply to all the code in the same file.Comment
Comment