带有显式模板实例化的extern关键字

时间:2017-04-04 13:33:48

标签: c++ c++11 visual-studio-2015

考虑我的问题的一个小调低用例,其中我有一个标题如下

#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

和源文件

#include "Header.h"

int main()
{
    myfoo f;
    f.func();
    return 0;
}

当我使用VS 2015(Update 3)编译时,我得到了warning

warning C4910: 'FOO<int>': '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation

MSDN页面没有向我解释为什么在显式模板声明中使用externdllexport是错误的。

有人可以解释一下这背后的理由是什么?

0 个答案:

没有答案
相关问题