Consider a small toned down use case of my problem wherein I have a header as follows
#include <iostream>
#pragma once
#ifndef HEADER_H
#define HEADER_H
template<typename T>
class FOO
{
public:
void func() { std::cout << "Foo!"; };
};
extern template class __declspec(dllexport) FOO<int>;
using myfoo = FOO<int>;
#endif
and a source file as
#include "Header.h"
int main()
{
myfoo f;
f.func();
return 0;
}
When I compile this with VS 2015 (Update 3), I get following warning
warning C4910: 'FOO<int>': '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation
MSDN page does not explain to me clearly why is it wrong to have extern
and dllexport
in explicit template declaration.
Can anybody please explain what is the rationale behind this ?