View Single Post
  #4   Spotlight this post!  
Unread 18-02-2012, 16:44
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: Functions in C++

Also there are a few other ways you could do what your trying to do (or what it looks like your trying to do)

Somewhere above your class you can declare a macro like this:

Code:
#include "WPILib.h"
//this will take a jaguar object (not a pointer to it) 
#define TURN_FOR_TIME(jagObj,speed,duration) {jagObj.Set(speed);Wait(duration);}
The way the above works is different from a function call in a few subtle (but important) ways, the way this works is anyplace you call TURN_FOR_TIME(...) it will essentially be like you actually typed all of the code inside the brackets (rather than jumping to a function and executing).

Macros are handy for doing simple operations like this in a way that looks nicer and more organized in your code

the following would do the exact same thing given the above #define
Code:
void TeleopContinuous(void) 
{
    //The second line is exactly what the compiler sees when you type the first line
    //The two lines are exactly the same, a macro is kinda like an automatic copy and paste
    TURN_FOR_TIME(myJag, 1.0, 2.0);
    {myJag.Set(1.0);Wait(2.0);};
}
Hope this helps (and isn't too much info )
Reply With Quote