I'm working on a project, where an application uses shared libraries as plugins.
I'm writing such a plugin and want to use a class with template members which is defined in the code of the main application:
template <class T>
What I'm wondering now is this:
The main application is compiled first. While doing so, the compiler extends the class definition everytime it encounters a new instantiation of the template member
doSomething(). The application is linked together as an executable containing
MyClass with all the different instantiations of the template that the compiler encountered.
Now the shared library (plugin) is compiled. Here, I instantiate a version of the template which was not instantiated in the code of the main application.
Now the plugin and the application have effectively different versions of
MyClass and I don't see how this could be resolved at compile-time.
What would happen, when the main application is started and it loads the shared library (plugin). What happens if I create an object of the libraries' version of
MyClass and pass it to the main application - they can't be compatible, right?