Extern keyword with explicit template creation
Consider a small toned use case of my problem where I have a header like this
#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 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 the following warning
warning C4910: 'FOO<int>': '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation
The MSDN page does not explain to me why it is wrong to have extern
and dllexport
in an explicit template declaration.
Can someone please explain what is the reason for this?
+3
Recker
source
to share
No one has answered this question yet
Check out similar questions:
2387
1643
1475
1399
961
563
340
293
18
3