So I have a dll which exports class which is derived from an explicitly instantiated (also exported) template.
parent.hpp
#pragma once
template <typename T>
struct parent {
parent(T t) m_t(t) {};
void print();
T m_t;
};
parent.cpp
template<typename T>
void parent<T>::print() {
cout << m_t << endl;
}
template class LIB_API parent<int>;
child.hpp
#include "parent.hpp"
extern template class parent<int>;
struct LIB_API child : public parent<int> {
using parent<int>::parent;
void some_method();
}
child.cpp defines some_method
So far everything is great and works. I can safely use the child class from targets which link with the dll. The problem comes when I use the child
class in the dll itself in another compilation unit:
some_other_dll_file.cpp:
void func()
{
child c(53);
c.print();
c.some_method();
}
In this case I get a warning: warning C4661: 'void parent<int>::print(void)': no suitable definition provided for explicit template instantiation request
(or in my particular case a ton of warnings for each and every method which is not visible in the template header in each and every file in the dll which uses the child class)
Note that it's a warning only. Eventually everything compiles and links, and works fine.
Is there a way to change the code so I don't get this warning?