I just can't wrap my head around on how to properly work with multiple files. My code has been getting quite big so I decided to split all the classes into one file each. So I'm left with 6 files:
dataHandler.cpp
fileHandler.cpp
header.cpp
main.cpp
request.cpp
sensorData.cpp
header.cpp includes all the header files, and main.cpp the setup() and loop() functions.
Visual Studio Code shows me no errors while compiling. The includeguards have the name convention: CLASSNAME_INCG
So in my main.cpp for example I have something like:
#ifndef HEADER_INCG
#include "header.cpp"
#define HEADER_INCG
#endif
#ifndef SENSORDATA_INCG
#include "SensorData.cpp"
#define SENSORDATA_INCG
#endif
#ifndef DATAHANDLER_INCG
#include "DataHandler.cpp"
#define DATAHANDLER_INCG
#endif
setup()
{
...
}
...
When going into a class-file I have it defined in the following way (fileHandler.cpp):
#ifndef HEADER_INCG
#include "header.cpp"
#define HEADER_INCG
#endif
#ifndef FILEHANDLER_INCG
#define FILEHANDLER_INCG
class FileHandler{
...
}
#endif
So in summary I include the headerfile into every file, with includeguards arround. If I wouldn't include it I would get errors that crucial libaries like Serial etc. are missing. But when including the header into every file compiliing works just fine, but when it comes to linking the files togehter I get an error of multiple definitions.
So how can I define the headerfile just once for all files albeit I need it in every file?