Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3301204
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:43:46+00:00 2026-05-17T20:43:46+00:00

I have a problem with a timer class based on a SDL timer. class

  • 0

I have a problem with a timer class based on a SDL timer.

class CTimer
{
    public:
    CTimer(): startTick(0), endTick(0), curTime(0), running(false) {};
    void Start() { startTick += SDL_GetTicks() - endTick; running = true; };
    void Stop() { endTick = SDL_GetTicks(); running = false; };
    void Reset() { startTick = 0; endTick = 0; curTime = 0; };
    inline int operator()() { return running ? curTime = ((int) SDL_GetTicks - startTick) / 1000 + 1 : curTime; };
    private:
    int startTick;
    int endTick;
    int curTime;
    bool running;
};

The () operator should return time in seconds (stored in curTime). But it always returns 4202 (curTime is always equal to that). What am I doing wrong?

Test code:

int main()
{
    SDL_Init (SDL_INIT_TIMER);
    CApp::CTimer timer;
    timer.Start();
    for (int i = 0; i < 15; ++i)
    {
        SDL_Delay (1000);
        std::cout << timer() << '\n';
    }
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:43:46+00:00Added an answer on May 17, 2026 at 8:43 pm

    This is a perfect example of why you don’t want to use old-style C casts in C++.

    (int) SDL_GetTicks
    

    The missing parentheses on the function call mean you’re casting a pointer to the function to an int, not the return value. Surprisingly enough the pointer to the function never changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a setup a PageHolder class (based on MovieCLip) that displays a doted
I have an abstract class Employee , and based on that, I created the
BACKGROUND: I have a GridView based on a fairly complex Adapter class which extends
I have a class along the lines of: public class Observation { private String
Suppose I have ViewModel like public class AnotherViewModel { public string Name { get;
I have a problem with time My server is in the USA and I'm
So I have run up against this problem a few times: I have some
I have spent too much time on this problem and am beginning to think
I have a bit of a problem. I wrote an API a long time
I have problem in some JavaScript that I am writing where the Switch statement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.