I'd like to use a library inside of a library I'm creating. Specifically, the ESP32 'Preferences' library. I have my external .h and .cpp files which contain my class, but I'm not sure where in my code I should instantiate the 'preferences' object, and where I should call the .begin() method? I have included the library I want to use in both the .h and .cpp, is that correct? Obviously I don't want to place any of this code within the main sketch so I can reuse this library.
Not sure a code snippet helps but can do if required.
Header file (.h)
Writes class declarations (including declarations of members and methods inside the class), function prototypes, #define constants, etc., but generally does not write out the concrete implementation.
It is important to note when writing header files that pre-compiled statements (as follows) must be added at the beginning and at the end in the following style.
#ifndef CIRCLE_H
#define CIRCLE_H
// Your code is written here
#endif
This is done to prevent duplicate compilation, without which there is a risk of errors.
As for the name CIRCLE_H, it doesn't really matter, you can call it whatever you want, as long as it conforms to the specification. In principle, it is highly recommended to write it in this form, because it is easier to correspond to the name of the header file.
Source file (.cpp) The source file mainly writes the specific code that implements those functions that have been declared in the header file. It is important to note that you must #include the implemented header file at the beginning, as well as the header file to be used. Then when you need to use the classes in the header file you wrote, you just need to #include them.