Home Using a template in a shared library
Reply: 0

Using a template in a shared library

LoveDaOOP
1#
LoveDaOOP Published in 2018-01-11 11:14:40Z

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:

class MyClass 
{
public:
    template <class T>
    T* doSomething();
}

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?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.329548 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO