|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
I found this inside of the WPI libary
PHP Code:
Code:
Timer::Timer(); Timer::Timer() means PHP Code:
Code:
error: cannot declare member function 'frc::Timer::Timer' within 'Robot'
Timer::Timer();
^
Thx. |
|
#2
|
||||
|
||||
|
Re: Help! Timer Function in WPIlib.h
Try using this instead: frc::Timer()
|
|
#3
|
||||
|
||||
|
Re: Help! Timer Function in WPIlib.h
Error
PHP Code:
|
|
#4
|
||||
|
||||
|
Re: Help! Timer Function in WPIlib.h
Timer is not a function. It is an object. This should work:
Code:
#include <IterativeRobot.h>
#include <Timer.h>
class Robot: public frc::IterativeRobot {
public:
void RobotInit() {
timer = new frc::Timer();
}
private:
frc::Timer* timer;
};
START_ROBOT_CLASS(Robot)
https://github.com/wpilibsuite/Eclip.../src/Robot.cpp |
|
#5
|
||||
|
||||
|
Re: Help! Timer Function in WPIlib.h
PHP Code:
Thx. |
|
#6
|
||||
|
||||
|
Re: Help! Timer Function in WPIlib.h
If you have a timer defined, you can Get() what its time is. For example,
Code:
timer = new frc::Timer(); timer.Reset(); timer.Start(); double time = timer.Get(); |
|
#7
|
||||
|
||||
|
Re: Help! Timer Function in WPIlib.h
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...
Code:
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 '.' pTimer->Reset(); pTimer->Start(); double timenow = pTimer->Get(); // Then eventually in your destructor you'd delete the pointer to "clean up" delete pTimer; Code:
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 '.') MyTimer.Reset(); MyTimer.Start(); double timenow = MyTimer.Get(); // No need to delete. It'll go away when it goes out of scope. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|