Help! Timer Function in WPIlib.h

I found this inside of the WPI libary


I put the line


into the code.
Timer::Timer() means

Create a new timer object.

Create a new timer object and reset the time to zero. The timer is initially not running and must be started.

When I built the code in eclipse, it came back with this error >

error: cannot declare member function 'frc::Timer::Timer' within 'Robot'

I don’t know why its doing this. If you know please tell.


Try using this instead: frc::Timer()


expected unqualified-id before ')' token

Timer is not a function. It is an object. This should work:

#include <IterativeRobot.h>
#include <Timer.h>

class Robot: public frc::IterativeRobot {
	void RobotInit() {
		timer = new frc::Timer();

	frc::Timer* timer;


And a more complete example:

double Timer::Get()const

also a object that needs to be declared? If so how?

If you have a timer defined, you can Get() what its time is. For example,

timer = new frc::Timer();


double time = timer.Get();

Almost … in C/C++, the use of pointers to objects versus actual objects themselves makes a confusing difference of the use of ‘.’ (objects) or the use of ‘->’ (pointer to an object). So, with all that said, what’s the rule? Here’s an example of using a pointer as was intended above…

frc::Timer *pTimer; // Note the use of 'p' notation just to let the reader know this is a pointer...

pTimer = new frc::Timer;
// Now let's use the timer (it's a pointer so we use '->' and not '.'

double timenow = pTimer->Get();
// Then eventually in your destructor you'd delete the pointer to "clean up"
delete pTimer;

The same piece of code but done with an object and NOT a pointer to an object would be…

frc::Timer MyTimer; // Note no 'p' preceeding - it's a real object - not a pointer. So there's no need to 'new' it either...

// Now let's use the timer (it's an object so we use '.')

double timenow = MyTimer.Get();
// No need to delete. It'll go away when it goes out of scope.

Thanks bob.wolf68. The timers work but… I have encountered a situation which is on a new thread.

Does anyone have a timer code that works like the one provided inside of WPIlib? The one in the WPI crashes the code every time :frowning: