CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Posts
    5

    Static Data Member

    When the momory will be allocated for a static data member in a class.


  2. #2
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Static Data Member

    during compilation / linking of your program

    sally


  3. #3
    Guest

    Re: Static Data Member

    hi,

    statics DONT get memory until u define the variable outside the class.
    Eg:
    class sample
    {
    int one;
    public:
    static int stat;
    };

    /*
    The statement below causes memory to be reserved, if u dont give this no problem, but u cant use the variable. This has been done because the static vars are not attached to any object and compiler has no idea when to create it so u have to create it !

    U can check this by printing sizeof(sample) with and without the static var and verify that!
    */
    int sample::stat=100;

    bye,


  4. #4
    Join Date
    Apr 1999
    Posts
    90

    Re: Static Data Member

    I believe static data members get allocated when you start the program so that they are available even if you don't allocate an object of that class.

    Later,
    Michael



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured