Static timer using Chrono

I'm trying to make a static timer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Timer.h
#include <chrono>
 struct Timer
{
	typedef std::chrono::steady_clock clock;
	typedef std::chrono::seconds seconds;

	static void reset(){start=clock::now();}
	static unsigned long long elapsed();
	static unsigned long long elapsedTotal();

private:
	static clock::time_point start;
	static const clock::time_point begin;
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//Timer.cpp

unsigned long long Timer::elapsed()
{
	typedef std::chrono::steady_clock clock;
	typedef std::chrono::seconds seconds;

	return std::chrono::duration_cast<seconds>(clock::now()-start).count();
}
unsigned long long Timer::elapsedTotal()
{
	typedef std::chrono::steady_clock clock;
	typedef std::chrono::seconds seconds;

	return std::chrono::duration_cast<seconds>(clock::now()-begin).count();
}

const std::chrono::steady_clock::time_point Timer::begin = std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point Timer::start = std::chrono::steady_clock::now();


This is nearly an exact copy of an example someone posted on these forums a while back. In that example nothing was static.

My problem is calling either of the elapsed functions looks to be returning a memory address, even though as far as I can tell that is not what count should be returning. Creating everything as a normal struct with no static members causes everything to work as expected. I can't figure out what's going wrong here.

Thanks.
> My problem is calling either of the elapsed functions looks to be returning a memory address
- you may have been calling the function incorrectly
- you may be misinterpreting the symptoms

http://www.eelis.net/iso-c++/testcase.xhtml
Topic archived. No new replies allowed.