A paragraph from Bjarne stroustrup's Book

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Visame
    New Member
    • Dec 2007
    • 7

    A paragraph from Bjarne stroustrup's Book

    How to understand the following paragraph from Bjarne stroustrup's The C++ Programming Language?
    9.4.1:
    In principle, a variable defined outside any function (that is, global, namespace, and class static variables) is initialized before main() is invoked. Such nonlocal variables in a translation unit are
    initialized in their declaration order (§10.4.9). If such a variable has no explicit initializer, it is by default initialized to the default for its type (§10.4.2). The default initializer value for builtin types and enumerations is 0 . For example:

    Does it mean:
    class Example
    {
    static int DataMember;
    }
    DataMember automatically intialized to 0.
    This seems to be wrong.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Youe have just declared a static member variable but you haven't defined it.

    When you define it, the default initialization will be 0.

    You might read this: http://www.thescripts.com/forum/thread737451.html.

    Comment

    Working...