Run Time initialisation of LIbraries?

Hi,
I have a 1284p board with 5 Mikroe 'Click' modules. The idea is that I can configure a range of different modules for reading various sensors with a variety of output options. This works absolutely fine as long as I hand build every combination, and by its very nature a certain degree of customisation is the reason I took this approach. However it is mostly that only 3-4 sensors are used in varying numbers per unit. eg 2xSensorA +2B,1xa+1B+3C etc giving a huge number of permutations. I would like to define the sensor type in EEPROM, and then initialise only the libraries needed, as in this psuedo code

Include LibA
Include LibB
include LibC
ModName[4] {V,W,X,Y,Z} //identifier for each module
ModType[4] // Type for each module read from EEPROM 1=LibA,2=LibB,3=LibC
Setup
ReadEEPROM
For I = 0 to 4
Type = ModType

  • Switch (Type)*
  • Case 1 // Use LibA*
    LibA ModName_(pinArray1*) // Initialise LibA with no of params required eg 1*
    * Case 2 etc............*
    I suspect that this cant be done at run time, but could I use a similar idea with a bunch of defines at the start to build unique system without having to cut and paste. It would make updating an impossibility without such a system I think.
    I have tried playing around with some C test code but it looks like I cant use a variable to initialise a library.
    I tried looking at the 'this' directive but I'm fairly new to C, and it caused my brain to hurt!!! If it can be done with 'this' is there a simple explanation on how?
    All suggestions gratefully received
    Steve_

Take a look at how the Adafruit Unified Sensor Library works. All sensor types inherit from a common base class allowing you to take advantage of OOP polymorphism.

Sensor objects can be created dynamically using the C++ 'new' operator.

Thank you for your reply, but that seems to be involved more involved in standardising the output, and would be very useful when using those libraries, not so much in invoking them.
Perhaps the answer does lie in OOP polymorphism and the C++ new operator, but as I said I'm fairly new to this C++ world. Is there an example somewhere of using for something like the stepper library and say servo library where in something like a 3D printer you could specify the library to use for each axis dependant on run/compile time options which would help me understand the workings of these functions.
Many thanks
Steve

You need to be more concrete. Provide an example of your code as it is now and explain specifically how you want it to be different. Also, provide GitHub links to any libraries you're using.

Finally, read this ... Read this before posting a programming question ... and be sure to post your code using Code Tags as described in Item #6.