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

  • Home
  • SEARCH
  • 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 4622970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:55:08+00:00 2026-05-22T02:55:08+00:00

Hey so i’m working on a stopwatch class using windows GetTickCount() and the STL,

  • 0

Hey so i’m working on a stopwatch class using windows GetTickCount() and the STL, but have run into a problem in that when implementing the Stopwatch(int DecNumb) constructor into the overload Stopwatch(int DecNumb, char command[]) the “accuracy” data type is not set correctly in the latter constructor.

(it seems to return to the former value of the unsigned long int 560345 or something…)

Here’s the class and main() commands i’m using to test it:

class Stopwatch
    {
    protected:
        int               accuracy;
        unsigned long int initial_ilu;
        unsigned long int current_ilu;
        long float        output_fl;
       vector<long float> times;

    public:
        Stopwatch(int DecNumb) { // so accuracy*10 isn't 0
                                    accuracy = 1;
                                for(;DecNumb>0;DecNumb--) // the Tick count will
                                accuracy = accuracy*10;}; // diveded by accuracy (each 0 in this number moves the decimal over once)
        Stopwatch(int aDecNumb, char command[]) {Stopwatch::Stopwatch(aDecNumb);
                                                 if(command = "start") Stopwatch::Start();}; 
        void Start(){initial_ilu = GetTickCount()/*/accuracy*/;};
        long float ElapsedTime()
        {
            current_ilu = GetTickCount()/*/accuracy*/;
            output_fl =  (current_ilu - initial_ilu)/accuracy;
            return output_fl;
        };
        void Wait(long float seconds) 
        {
            for(unsigned long int waitTime = GetTickCount() + (seconds*accuracy);
                waitTime > GetTickCount();) {}
            // stay stuck in for loop until time specified is up
        };

        void SaveTime(){times.push_back(GetTickCount()/*/accuracy*/);};
        long float GetTime(int location){if(times.size()<location+1) return times[location+1];
                                         else return -1;};

    };

And here’s main()

int main()
    {
        Stopwatch myStopwatch(3,"start");
        for(;;)
        {
            myStopwatch.Wait(2);
            cout << myStopwatch.ElapsedTime() << endl;
        }
                return 0;
    }

Why is accuracy not staying at the value i set it too in the constructor? Thanks! =)
oh and any other feedback on my code is welcome! (i’m rather new)

  • 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-22T02:55:09+00:00Added an answer on May 22, 2026 at 2:55 am
    Stopwatch::Stopwatch(aDecNumb);
    

    This does not call the other constructor; it isn’t even valid C++.

    You can’t call one constructor from another constructor for the same object. Only one constructor is called during the creation of an object (not including base class or member constructors, of course).

    You don’t really need two constructors here, though; one will suffice:

    Stopwatch(int DecNumb, char* command = 0) {
        accuracy = 1;
        for(; DecNumb > 0; DecNumb--) {
            accuracy = accuracy * 10;
        }
    
        if (command && std::string(command) == "start") {
            Start();
        }
    }
    

    If you really do need two constructors, your best bet is either to use a base class that performs initialization that is common to multiple constructors or to use an “initialize” member function that can be called from the multiple constructors.

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

Sidebar

Related Questions

Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey right now I'm using jQuery and I have some global variables to hold
Hey I'm building an app that will allow a user to log into a
Hey everyone I have a basic search function here that allows me to search
Hey all i have an XML file that i am trying to loop though.
Hey guys here is my question. im using JCombobox. if a student have CB
Hey, I have a problem sharing a link on twitter: data-url=http://ipofmywebsite/mypage/?some_id=276&some_name=b+a As I put
Hey im programming a simple game using directX and C++ and i have hit
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also
Hey, I've been developing an application in the windows console with Java, and want

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.