I’m working on a project and I wanted to use multiple files, and I’m having trouble wrapping my head around this issue I’m running into. What I want to do is have my autonomous routines in a separate file, and I’m getting an error when trying to reference my motors.
In main.h I extern my motor:
extern pros::Motor LiftMotor;
In main.cpp I include my main.h header file and declare my motor (I’m not too familiar with the proper terminology so please correct me if I slip up)
What is happening is that first, the compiler would put all the contents of main.h at the top. Then when compiling, it works it’s way from top to bottom. When it reaches your extern statement, the compiler had not seen the declaration yet. Our colution to this is to make another hedder, and include your externs their. And in every cpp file EXCEPT the one the motors are declared in, include both, main.h and your new file