I'm trying to compile a code similar to the following one, it is part of a library dll which I'm trying to compile with MS Visual Compiler :
#include <iostream>
#include <map>
#include <string>
#include <memory>
struct B {
};
template <typename T>
class TemplateClass {
public:
void print() {
std::cout << "Hello, world!\n";
}
private:
std::map<std::string, std::unique_ptr<T>> m_map;
};
template class __declspec(dllexport) TemplateClass<B>;
int main()
{
TemplateClass<B> test;
test.print();
return 0;
}
The compilation fails with the following error :
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xmemory0(655): error C2280: 'std::pair<const _Kty,_Ty>::pair(const std::pair<const _Kty,_Ty> &)': attempting to reference a deleted function
with
[
_Kty=std::string,
_Ty=std::unique_ptr<B,std::default_delete<B>>
]
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\utility(96): note: see declaration of 'std::pair<const _Kty,_Ty>::pair'
with
[
_Kty=std::string,
_Ty=std::unique_ptr<B,std::default_delete<B>>
]
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xmemory0(773): note: see reference to function template instantiation 'void std::allocator<_Other>::construct<_Objty,_Ty&>(_Objty *,_Ty &)' being compiled
with
[
_Other=std::_Tree_node<std::pair<const std::string,std::unique_ptr<B,std::default_delete<B>>>,void *>,
_Objty=std::pair<const std::string,std::unique_ptr<B,std::default_delete<B>>>,
_Ty=std::pair<const std::string,std::unique_ptr<B,std::default_delete<B>>>
]
...
I cannot find out what's wrong with this simple code.
If I remove __declspec(dllexport)
, it compiles and executes perfectly.
Thank you in advance for your help.