![]() |
Functions in C++
If i was to create a header file that would control a motor would i declare it as such:
#ifndef CODE_H #define CODE_H #include "WPILib.h" class Code { private: Timer Time; public: Code(); void TurnForTime(Jaguar* Jag,float speed, float time); void Wait(float time); ~Code(); }; #endif |
_____________________
|
Re: Functions in C++
As a quick note, when you post code, if you the CODE tags (click the # button in the post formatting options), you can post code much prettier formatting.
Code:
#ifndef CODE_HWhen you call the function TurnForTime, your syntax would look like this: codeObject.TurnForTime(&myJagObject,1.0,5.0); But... if this is the actual header file you are creating (to go along with some cpp file) then I'd like to caution you on a few things: a) Code is a bad name to give anything, while it may seem nitpicky to say this, it's very important to be as descriptive as possible with what you call things. b) The Wait function you have shown is already provided by the WPILib; and using a wait function will keep all other code from executing (so your motors will continue running a particular speed until the blocking ends), which is ok as long as your doing it on purpose ;) c) If your doing this because your having trouble adding a regular function outside of the ones provided by the template, then this is a bit overkill (I remember one of your prev post, so I'm just checkin :) ). If you'd like a bit of help with structuring whatever it is your trying to do, feel free to PM me with a description of what your doing and your robot.cpp code(or post the code here) and I can try to help. |
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"Macros are handy for doing simple operations like this in a way that looks nicer and more organized in your code :D the following would do the exact same thing given the above #define Code:
|
| All times are GMT -5. The time now is 17:33. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi