vendredi 20 septembre 2019

C++11 and C++03 intercompatibility

I have the following situation, expressed by the following diagram:

enter image description here

Consumer and Data are both compiled as two different static libraries, and thus linked statically to Service, that represents an executable. Service is just a characteristic type of this executable. Everything has been compiled using C++03 so far.

The Service object creates and holds a instance of Data and Consumer. First it creates Data, and then creates Consumer, passing Data as a constructor parameter by reference. Both Service and Consumer can call anytime virtual_method(), and Data is actually the most derived member of a short polymorphic hierarchy.

Now, I need to add to Data some C++11 features that are going to be used exclusively by Service. The static library must not be compiled with C++11, because it causes linking problems due to old and poorly designed Makefiles that I won't modify for my own sake.

So, in order to isolate compilation, what I've thought is to extend Data in the following way:

enter image description here

The idea is to compile Service and DataE with C++11, while keeping Data and Consumer compiled statically with C++03. Basically, the DataE class will contain a signaling mechanism (boost::signal alike) so, whenever virtual_method is called from Data, DataE will emit the signal and all installed callbacks will be called.

The pupose is to allow to new Service componentes to sniff Data changes by connecting callbacks and act according to their own purposes using C++11 without affecting the static library.

Is there any involved risks with this approach, in terms of C++ versioning compatibility, taken into account the polymorphic interface?

Aucun commentaire:

Enregistrer un commentaire