Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problems with static members

problems with static members

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharphtmlquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Ylis
    wrote on last edited by
    #1

    I'm having some trouble with static members in my program. This is what my code looks like: #ifndef TIMER_H #define TIMER_H class Timer { private: static LARGE_INTEGER m_lTicksPerSecond; static LARGE_INTEGER m_lTime; static LARGE_INTEGER m_lFirstTime; Timer(); public: static bool Initialize() { if(QueryPerformanceFrequency(&m_lTicksPerSecond) && QueryPerformanceCounter(&m_lFirstTime)) return true; return false; } static double MsSinceStart() { QueryPerformanceCounter(&m_lTime); return ((double)(m_lTime.QuadPart - m_lFirstTime.QuadPart ) / (double)m_lTicksPerSecond.QuadPart ) * 1000.0; } }; #endif Or you can check it out at http://www.rafb.net/paste/results/SD400728.html (don't know if codeproject supports the formating). Anyway, the error I'm geting is: error LNK2001: unresolved external symbol "private: static union _LARGE_INTEGER Timer::m_lFirstTime" (?m_lFirstTime@Timer@@0T_LARGE_INTEGER@@A) on every member. The program it self is a win32 application. Grateful for any help ;)

    R J 2 Replies Last reply
    0
    • Y Ylis

      I'm having some trouble with static members in my program. This is what my code looks like: #ifndef TIMER_H #define TIMER_H class Timer { private: static LARGE_INTEGER m_lTicksPerSecond; static LARGE_INTEGER m_lTime; static LARGE_INTEGER m_lFirstTime; Timer(); public: static bool Initialize() { if(QueryPerformanceFrequency(&m_lTicksPerSecond) && QueryPerformanceCounter(&m_lFirstTime)) return true; return false; } static double MsSinceStart() { QueryPerformanceCounter(&m_lTime); return ((double)(m_lTime.QuadPart - m_lFirstTime.QuadPart ) / (double)m_lTicksPerSecond.QuadPart ) * 1000.0; } }; #endif Or you can check it out at http://www.rafb.net/paste/results/SD400728.html (don't know if codeproject supports the formating). Anyway, the error I'm geting is: error LNK2001: unresolved external symbol "private: static union _LARGE_INTEGER Timer::m_lFirstTime" (?m_lFirstTime@Timer@@0T_LARGE_INTEGER@@A) on every member. The program it self is a win32 application. Grateful for any help ;)

      R Offline
      R Offline
      Robert A T Kaldy
      wrote on last edited by
      #2

      You should define all static members in the timer.cpp file, e.g. LARGE_INTEGER Timer::m_lTime;. Robert-Antonio

      Y 1 Reply Last reply
      0
      • Y Ylis

        I'm having some trouble with static members in my program. This is what my code looks like: #ifndef TIMER_H #define TIMER_H class Timer { private: static LARGE_INTEGER m_lTicksPerSecond; static LARGE_INTEGER m_lTime; static LARGE_INTEGER m_lFirstTime; Timer(); public: static bool Initialize() { if(QueryPerformanceFrequency(&m_lTicksPerSecond) && QueryPerformanceCounter(&m_lFirstTime)) return true; return false; } static double MsSinceStart() { QueryPerformanceCounter(&m_lTime); return ((double)(m_lTime.QuadPart - m_lFirstTime.QuadPart ) / (double)m_lTicksPerSecond.QuadPart ) * 1000.0; } }; #endif Or you can check it out at http://www.rafb.net/paste/results/SD400728.html (don't know if codeproject supports the formating). Anyway, the error I'm geting is: error LNK2001: unresolved external symbol "private: static union _LARGE_INTEGER Timer::m_lFirstTime" (?m_lFirstTime@Timer@@0T_LARGE_INTEGER@@A) on every member. The program it self is a win32 application. Grateful for any help ;)

        J Offline
        J Offline
        John M Drescher
        wrote on last edited by
        #3

        Did you define m_lTicksPerSecond, m_lTime,m_lFirstTime and in your cpp file.

        // In Timer.cpp
        LARGE_INTEGER Timer::m_lTicksPerSecond=0;
        LARGE_INTEGER Timer::m_lTime=0;
        LARGE_INTEGER Timer::m_lFirstTime=0;

        Also have you checked out this: http://www.naughter.com/cputicker.html[^] Removing the mfc part only takes a few seconds... John

        Y 1 Reply Last reply
        0
        • R Robert A T Kaldy

          You should define all static members in the timer.cpp file, e.g. LARGE_INTEGER Timer::m_lTime;. Robert-Antonio

          Y Offline
          Y Offline
          Ylis
          wrote on last edited by
          #4

          I'm sorry but I can't get it to work :/ When I place LARGE_INTEGER Timer::m_lTime etc inside my .cpp file it begins to talk about redefinition errors. If I remove LARGE_INTEGER m_lTime etc from my .h file it says 'm_lTime' : is not a member of 'Timer'. could you write just a simple class with a static member explaining it to me? :)

          1 Reply Last reply
          0
          • J John M Drescher

            Did you define m_lTicksPerSecond, m_lTime,m_lFirstTime and in your cpp file.

            // In Timer.cpp
            LARGE_INTEGER Timer::m_lTicksPerSecond=0;
            LARGE_INTEGER Timer::m_lTime=0;
            LARGE_INTEGER Timer::m_lFirstTime=0;

            Also have you checked out this: http://www.naughter.com/cputicker.html[^] Removing the mfc part only takes a few seconds... John

            Y Offline
            Y Offline
            Ylis
            wrote on last edited by
            #5

            oki, I checked out the cputicker class but still can't figure out what I'm doing wrong, perhaps I'm geting blind to my code. This is what my 2 files looks like now: Timer.h #ifndef TIMER_H #define TIMER_H class Timer { protected: static LARGE_INTEGER m_lTicksPerSecond; static LARGE_INTEGER m_lTime; static LARGE_INTEGER m_lFirstTime; Timer(); public: static bool Initialize(); static double MsSinceStart(); }; #endif and this is what Timer.cpp looks like: #include "Timer.h" LARGE_INTEGER Timer::m_lTicksPerSecond = NULL; LARGE_INTEGER Timer::m_lFirstTime = NULL; LARGE_INTEGER Timer::m_lTime = NULL; bool Timer::Initialize() { if(QueryPerformanceFrequency(&m_lTicksPerSecond) && QueryPerformanceCounter(&m_lFirstTime)) return true; return false; } double Timer::MsSinceStart() { QueryPerformanceCounter(&m_lTime); return ((double)( m_lTime.QuadPart - m_lFirstTime.QuadPart ) / (double) m_lTicksPerSecond.QuadPart ) * 1000.0; } and this is the error which seems relevant: error C2039: 'm_lFirstTime' : is not a member of 'Timer' (which it as you see is) hehe, plz bare with me ;P

            J R 2 Replies Last reply
            0
            • Y Ylis

              oki, I checked out the cputicker class but still can't figure out what I'm doing wrong, perhaps I'm geting blind to my code. This is what my 2 files looks like now: Timer.h #ifndef TIMER_H #define TIMER_H class Timer { protected: static LARGE_INTEGER m_lTicksPerSecond; static LARGE_INTEGER m_lTime; static LARGE_INTEGER m_lFirstTime; Timer(); public: static bool Initialize(); static double MsSinceStart(); }; #endif and this is what Timer.cpp looks like: #include "Timer.h" LARGE_INTEGER Timer::m_lTicksPerSecond = NULL; LARGE_INTEGER Timer::m_lFirstTime = NULL; LARGE_INTEGER Timer::m_lTime = NULL; bool Timer::Initialize() { if(QueryPerformanceFrequency(&m_lTicksPerSecond) && QueryPerformanceCounter(&m_lFirstTime)) return true; return false; } double Timer::MsSinceStart() { QueryPerformanceCounter(&m_lTime); return ((double)( m_lTime.QuadPart - m_lFirstTime.QuadPart ) / (double) m_lTicksPerSecond.QuadPart ) * 1000.0; } and this is the error which seems relevant: error C2039: 'm_lFirstTime' : is not a member of 'Timer' (which it as you see is) hehe, plz bare with me ;P

              J Offline
              J Offline
              John M Drescher
              wrote on last edited by
              #6

              I am not sure what the problem is. Check to make sure that your cpp file is indeed included in your project and it is compiling... As for the link, since I saw you were trying to do some work with high resolution timers I thought the code there may save you some work... John

              1 Reply Last reply
              0
              • Y Ylis

                oki, I checked out the cputicker class but still can't figure out what I'm doing wrong, perhaps I'm geting blind to my code. This is what my 2 files looks like now: Timer.h #ifndef TIMER_H #define TIMER_H class Timer { protected: static LARGE_INTEGER m_lTicksPerSecond; static LARGE_INTEGER m_lTime; static LARGE_INTEGER m_lFirstTime; Timer(); public: static bool Initialize(); static double MsSinceStart(); }; #endif and this is what Timer.cpp looks like: #include "Timer.h" LARGE_INTEGER Timer::m_lTicksPerSecond = NULL; LARGE_INTEGER Timer::m_lFirstTime = NULL; LARGE_INTEGER Timer::m_lTime = NULL; bool Timer::Initialize() { if(QueryPerformanceFrequency(&m_lTicksPerSecond) && QueryPerformanceCounter(&m_lFirstTime)) return true; return false; } double Timer::MsSinceStart() { QueryPerformanceCounter(&m_lTime); return ((double)( m_lTime.QuadPart - m_lFirstTime.QuadPart ) / (double) m_lTicksPerSecond.QuadPart ) * 1000.0; } and this is the error which seems relevant: error C2039: 'm_lFirstTime' : is not a member of 'Timer' (which it as you see is) hehe, plz bare with me ;P

                R Offline
                R Offline
                Robert A T Kaldy
                wrote on last edited by
                #7

                How is LARGE_INTEGER defined? Aren't there any macros that interfere with your variable names? The simple example of declaring static members is: pruba.h:

                class A
                {
                static int b;
                };

                pruba.cpp:

                #include "pruba.h"

                int A::b = 1;

                Robert-Antonio "Science is a differerntial equation. Religion is a boundary condition."

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups