static vairaible in class templates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • santoshramancha
    New Member
    • Mar 2008
    • 7

    #1

    static vairaible in class templates

    what is the output If there is one class template which has one static member variable ?
  • MACKTEK
    New Member
    • Mar 2008
    • 40

    #2
    can you be more specific, maybe add an example.

    Comment

    • santoshramancha
      New Member
      • Mar 2008
      • 7

      #3
      Originally posted by MACKTEK
      can you be more specific, maybe add an example.
      i mean can we add a static vairaible in a class template, if we can add what is the possibility:
      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

      • MACKTEK
        New Member
        • Mar 2008
        • 40

        #4
        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

        Working...