Results 1 to 5 of 5

Thread: Initializing a static varible

  1. #1

    Thread Starter
    Addicted Member NOMADMAN's Avatar
    Join Date
    Aug 2002
    Location
    Closer than you think
    Posts
    237

    Initializing a static varible

    If I have a class that has a private static varible (say and int statInt) how do I initialize it. I can't do it in constructor because it exists for all class obj...

    What is the correct syntax for this?

    NOMAD

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Code:
    class a
    {
    private:
       static int v;
    public:
       void m();
    };
    
    int a::v = 0;
    
    void a::m()
    {
    
    }
    Z.

  3. #3

    Thread Starter
    Addicted Member NOMADMAN's Avatar
    Join Date
    Aug 2002
    Location
    Closer than you think
    Posts
    237
    oh well i guess that logical (*wink*)

    NOMAD

  4. #4

    Thread Starter
    Addicted Member NOMADMAN's Avatar
    Join Date
    Aug 2002
    Location
    Closer than you think
    Posts
    237
    And if I placed the static varible in the public section could I do a::v = 0 from my main? If so does it require an instance of the class to be instanciated? Then would I use the the . operator?

    NOMAD

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No, it's the same syntax no matter what the visibility is.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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