Thread: problem with static integers

  1. #1
    Join Date
    Jan 2003

    problem with static integers

    I can't seem to get a static integer in one class to be incremented in the constructor of another class. Is it legal to do this, or am I just doing something syntactically wrong?

    the constructor looks like this:

    classname() {classname::variablename++;}

    would that be correct? Yes the static integer is public

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    Sure, you can do that. But you should post a more complete example of how you are attempting this.
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

  3. #3
    Join Date
    Jan 2003
    well I just worked my way around the problem by having an 'add' method in the owner class which calls push_back on the vector and increments its own static integer variable instead of having the owned structure do it in the constructor

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    if a variable is declared static in a function, it can only be accessed in that functin, if it is declared in a class, it must be public to access it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  2. Linking errors with static var
    By Elysia in forum C++ Programming
    Replies: 8
    Last Post: 10-27-2007, 05:24 PM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM