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 6103607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:44:52+00:00 2026-05-23T13:44:52+00:00

I have the following code and I wanted to create a class that encapsulates

  • 0

I have the following code and I wanted to create a class that encapsulates the timer but the trouble I’m having is using the timer after declaring the class. I posted another block of code to show an example of how I want to use the timer.

double diffclock(clock_t clock1,clock_t clock2)
{
    double diffticks=clock1-clock2;
    double diffms=(diffticks*1000)/CLOCKS_PER_SEC;
    return diffms;
}
void some_function()
{   
    clock_t begin = clock();

    //do something
    clock_t end=clock();
    cout << "Time elapsed: " << double(diffclock(end,begin)) << " ms"<< endl;

}

this is the header file

#ifndef SPECIALCLOCK_H
#define SPECIALCLOCK_H
#include <ctime>

class specialclock
{
    private:

    public:

    specialclock(){}
    ~specialclock(){}
    double diffclock(clock_t clock1,clock_t clock2);
};
double specialclock::diffclock(clock_t clock1,clock_t clock2)
{
    double diffticks=clock1-clock2;
    double diffms=(diffticks*1000)/CLOCKS_PER_SEC;
    return diffms;
}
#endif

And this the the main file

#include "specialclock.h"

int main()
{

   specialclock timer;

//how would I use the timer here?

   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-23T13:44:53+00:00Added an answer on May 23, 2026 at 1:44 pm

    The way you have your class set up doesn’t really make sense. I have a simple timer class that works like this:

    Timer MyTimer;
    
    // Do stuff...
    
    std::cout << "Execution took " << MyTimer.Seconds() << " seconds." << std::endl;
    

    Is this what you’re looking for? If so, my class is set up like the following:

    class Timer
    {
        std::clock_t ReferencePoint;
    
        public:
    
        Timer()
        {
            // Set the reference point to the current time.
        }
    
        double Seconds()
        {
            // Return the difference between the current time and the
            // reference point.
        }
    };
    

    This is simplified for the sake of clarity. You can see my full source here and here.

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

Sidebar

Related Questions

I have following code snippet that i use to compile class at the run
I have following code class User attr_accessor :name end u = User.new u.name =
I have the following piece of code, just wanted to check who will call
I have the following code. I set up and alarm in HelloAndroid2.java, and after
I'm using EF 4.1 code first. Given the following class snippet: public class Doctor
I have following matrix wanted to create heatmap in R E1 E2 P1 P2
So I essentially have the following code. I had working code and wanted to
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I have following code in my application: // to set tip - photo in

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.