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
c ++ c ++ 11 visual-studio-2015


source to share


No one has answered this question yet

Check out similar questions:

2387
What does an explicit keyword mean?
1643
Why templates can only be implemented in a header file?
1475
What is the effect of extern "C" in C ++?
1399
What is undefined link / unresolved external symbol error and how to fix it?
961
Where and why do I need to put the keywords "pattern" and "name-type"?
563
Use 'class' or 'typename' for template parameters?
340
C ++ typedef template
293
Difference between keywords "typename" and "class" in templates?
18
How to separate definition from declaration for class template using "extern" in C ++ 11 in a library (dll, so, ..)
3
std :: declval () firing assertion error with warnings in GCC



All Articles
Loading...
X
Show
Funny
Dev
Pics