View Single Post
  #7   Spotlight this post!  
Unread Today, 00:17
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 162
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
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;
The same piece of code but done with an object and NOT a pointer to an object would be...
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.
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote