I’m currently stumbled upon an issue; i have an external library written in C++ using templates a lot, a “black box” for me whose i can see the code and not implement over.
I’m using instances of classes defined in that library, and i want to modify some protected fields, for my uses of the interface, of these instances and clearly there aren’t setter and getter provided.
Which is the best way to face this problem?
A first solution could be, implement a subclass of one of the class i am interested in and define getter/setter for stuff of the BaseClass fields. I don’t know if there is a way in C++ like in Java to use static types and dynamic types like this:
BaseClass A = new Subclass();
in such a way to use method defined in the subClass keeping BaseClass type the generic use of the class itself.
I am expecting to modify some of the fields in the BaseClass for use in my interface with this library, to handle an external library data structure in a way that is transparent to the external library.
Clearly maintaining consistency with what is expressed in the constraints of these structures.