Thread: static int class question...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    63

    static int class question...

    just got out of an exam.. if i have a static int declared in one class and its updated each time a new object is created within that class is that int updated for each of the old class objects as well?

    so say i have a class ball.. and there is a static in numballs.. and each time i create a new ball i increment numballs by one.. will the first ball's numballs value always increment each time a new ball is created?

    lookin for some piece of mind here..

    thanks
    SS3X

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    There is only 1 copy of a static variable for all the objects in your class. So if that static variable was incremented then that would affect all objects of that class.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    The static int is available in all balls created but technically there is only one copy, it's not updated in each of the balls created.

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    thanks got that question right..
    SS3X

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  2. [GLUT] Pointers to class methods
    By cboard_member in forum C++ Programming
    Replies: 13
    Last Post: 02-16-2006, 04:03 PM
  3. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM