In cpp (that’s what VEXcode uses)
#include includes other source file into your program. You can imagine it as coping and pasting the file right where the include statement is. So first off the
.cpp endings don’t actually have to be used, it is just a convention everyone uses but it makes things easier to understand so please use it. The
.h is header files (other link), which should contain declarations, which, for example, give a function name and it’s parameters. The function body is then declared in the
This would look something like this...
It is also convention to name the files the same name…
#pragma once //I'll explain this later
int myAwesomeFunction(int number); //declaration
int myAwesomeFunction2(int number); //declaration
int myAwesomeFunction(int number) //definition
return number + 1;
int stuff::myAwesomeFunction2(int number) //definition
return number + 2;
The reason it is done like this is to be able to look at a header file and see all the function/class/variables without lots of code making things more confusing.
Also only header files ever need to be included.
The problem you are having is that you are declaring the same thing multiple time. In
main.cpp you include
vex.h which already includes your autonomous functions. Then you included your autonomous function again in
First you don’t need to include it in the
main.cpp since it is already included in
vex.h. The error should go away at this point, but you are not done. To avoid the problem of redefining anything something called include guards are used. They are necessary for more complex program where you have multiple includes of the same file, which technicaly aren’t necessary, but make life easier. Never the less you should just use them. The simplest way to do this is using
This is completely up to you and anything would work.
I would probably separate them into
.cpp files if you have many/multiple functions so that you can see them all in a small file. If you are planning on have just one function it would probably be easier to just have one
.cpp file (you can still use
#program once) and include it in
Also to access your motor ports (which I assume you declared in
vex.h) you should include
vex.h in the autonomous routine file(s).