1 2 3 4 5 6 7 8 9
|
class State
{
public:
State();
protected:
private:
std::unordered_map<std::string,std::unique_ptr<int>> objects;
};
|
This code will not compile. CodeBlocks gives me
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\hashtable_policy.h||In instantiation of 'std::__detail::_Hash_node<_Value, true>::_Hash_node(_Args&& ...) [with _Args = {const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<int, std::default_delete<int> > >&}; _Value = std::pair<const std::basic_string<char>, std::unique_ptr<int> >]':|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ext\new_allocator.h|120|required from 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::__detail::_Hash_node<std::pair<const std::basic_string<char>, std::unique_ptr<int> >, true>; _Args = {const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<int, std::default_delete<int> > >&}; _Tp = std::__detail::_Hash_node<std::pair<const std::basic_string<char>, std::unique_ptr<int> >, true>]'|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\hashtable.h|727|required from 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::__node_type* std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::_M_allocate_node(_Args&& ...) [with _Args = {const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<int, std::default_delete<int> > >&}; _Key = std::basic_string<char>; _Value = std::pair<const std::basic_string<char>, std::un|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\hashtable.h|898|required from 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::_Hashtable(const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>&) [with _Key = std::basic_string<char>; _Value = std::pair<const std::basic_string<char>, std::unique_ptr<int> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>, std::unique_ptr<int> > >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::basi|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\hashtable.h|425|required from 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>& std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::operator=(const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>&) [with _Key = std::basic_string<char>; _Value = std::pair<const std::basic_string<char>, std::unique_ptr<int> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>,|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\unordered_map.h|97|required from here|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\hashtable_policy.h|177|error: use of deleted function 'constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const std::basic_string<char>; _T2 = std::unique_ptr<int>]'|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_pair.h|127|note: 'constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const std::basic_string<char>; _T2 = std::unique_ptr<int>]' is implicitly deleted because the default definition would be ill-formed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_pair.h|127|error: use of deleted function 'std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int; _Dp = std::default_delete<int>]'|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\unique_ptr.h|273|error: declared here|
||=== Build failed: 3 error(s), 9 warning(s) (0 minute(s), 1 second(s)) ===|
Strangely, the code compiles when the unordered_map declaration is moved to the main function. Why is this happening?