Sorry if this seems to be a beginner question, but I can't seem to work out the best approach for my C++ library. I have build a static library, which contains driver API handling code. Currently in order to use it in a higher layer of the software (a simple app with GUI), I need to link the library to the project and create a new instance of a class which exists in this library to access all of its public methods. When a new instance of this class is created, all necessary objects required by the code to work are initialized. I would like to skip the instantiation step and enable the potential users to have it working only by including the library in their code. To picture this better, here's a code example:
What I currently have:
#include "myLibrary.h"
// Some GUI code here
MyLibrary *mLib;
mLib = new MyLibrary;
// Using the library methods
mLib->startProcess();
What I would like to have:
#include "myLibrary.h"
MyLibrary::startProcess();
I am working in Qt Creator, but don't mind migrating to a different IDE (Visual Studio would also be fine). The files I have in this projects are:
- MyLibrary.h (declarations)
- MyLibrary_global.h (an include list and export settings created by Qt Creator)
- MyLibrary.cpp (implementation)
Any help would be appreciated. In case further clarification on my issue is needed, I will edit this question to make it clear.
EDIT: After digging in the driver API documentation, I have found out, that the way it is implemented will require me to create an instance of the MyLibrary class. I have gotten plenty knowledge from the comments below and marked the singleton-response as valid, since that would be the way for me to proceed if it was possible.