這個坑其實我早就知道,只不過是沒有這個數據就會自動創建而已,頂多是一些錯誤數據而已,今天竟然出現了編譯錯誤!!!我特么還以為是構造函數的問題,查了一小時。我平時map用的很少,都是unordered_map,但是如果數據量小,哈希的效率還沒有紅黑樹高,我就換了map,開始的時候看到源碼中用的中括號,我就用了,也過了,就沒當回事,后來自己大改,編譯錯誤就出現了。
報的這個錯誤
In instantiation of ‘std::pair
<_T1, _T2
>::pair
(std::tuple
<_Args1
...
>&, std::tuple
<_Args2
...
>&, std::_Index_tuple
<_Indexes1
...
>, std::_Index_tuple
<_Indexes2
...
>) [with _Args1
= {const int
&}; unsigned int
..._Indexes1
= {0u
}; _Args2
= {}; unsigned int
..._Indexes2
= {}; _T1
= const int
; _T2
= thread_graphic
]’:
/opt/hisi-linux/x86-arm/arm-himix200-linux/arm-linux-gnueabi/include/c++/6.3.0/tuple:1575:63: required from ‘std::pair
<_T1, _T2
>::pair
(std::piecewise_construct_t, std::tuple
<_Args1
...
>, std::tuple
<_Args2
...
>) [with _Args1
= {const int
&}; _Args2
= {}; _T1
= const int
; _T2
= thread_graphic
]’
/opt/hisi-linux/x86-arm/arm-himix200-linux/arm-linux-gnueabi/include/c++/6.3.0/ext/new_allocator.h:120:4: required from ‘void __gnu_cxx::new_allocator
<_Tp
>::construct
(_Up*, _Args
&& ...
) [with _Up
= std::pair
<const int, thread_graphic
>; _Args
= {const std::piecewise_construct_t
&, std::tuple
<const int
&>, std::tuple
<>}; _Tp
= std::_Rb_tree_node
<std::pair
<const int, thread_graphic
> >]’
/opt/hisi-linux/x86-arm/arm-himix200-linux/arm-linux-gnueabi/include/c++/6.3.0/bits/alloc_traits.h:455:4: required from ‘static void std::allocator_traits
<std::allocator
<_CharT
> >::construct
(std::allocator_traits
<std::allocator
<_CharT
> >::allocator_type
&, _Up*, _Args
&& ...
) [with _Up
= std::pair
<const int, thread_graphic
>; _Args
= {const std::piecewise_construct_t
&, std::tuple
<const int
&>, std::tuple
<>}; _Tp
= std::_Rb_tree_node
<std::pair
<const int, thread_graphic
> >; std::allocator_traits
<std::allocator
<_CharT
> >::allocator_type
= std::allocator
<std::_Rb_tree_node
<std::pair
<const int, thread_graphic
> > >]’
/opt/hisi-linux/x86-arm/arm-himix200-linux/arm-linux-gnueabi/include/c++/6.3.0/bits/stl_tree.h:543:32: required from ‘void std::_Rb_tree
<_Key, _Val, _KeyOfValue, _Compare, _Alloc
>::_M_construct_node
(std::_Rb_tree
<_Key, _Val, _KeyOfValue, _Compare, _Alloc
>::_Link_type, _Args
&& ...
) [with _Args
= {const std::piecewise_construct_t
&, std::tuple
<const int
&>, std::tuple
<>}; _Key
= int
; _Val
= std::pair
<const int, thread_graphic
>; _KeyOfValue
= std::_Select1st
<std::pair
<const int, thread_graphic
> >; _Compare
= std::less
<int
>; _Alloc
= std::allocator
<std::pair
<const int, thread_graphic
> >; std::_Rb_tree
<_Key, _Val, _KeyOfValue, _Compare, _Alloc
>::_Link_type
= std::_Rb_tree_node
<std::pair
<const int, thread_graphic
> >*
]’
/opt/hisi-linux/x86-arm/arm-himix200-linux/arm-linux-gnueabi/include/c++/6.3.0/bits/stl_tree.h:560:4: required from ‘std::_Rb_tree_node
<_Val
>* std::_Rb_tree
<_Key, _Val, _KeyOfValue, _Compare, _Alloc
>::_M_create_node
(_Args
&& ...
) [with _Args
= {const std::piecewise_construct_t
&, std::tuple
<const int
&>, std::tuple
<>}; _Key
= int
; _Val
= std::pair
<const int, thread_graphic
>; _KeyOfValue
= std::_Select1st
<std::pair
<const int, thread_graphic
> >; _Compare
= std::less
<int
>; _Alloc
= std::allocator
<std::pair
<const int, thread_graphic
> >; std::_Rb_tree
<_Key, _Val, _KeyOfValue, _Compare, _Alloc
>::_Link_type
= std::_Rb_tree_node
<std::pair
<const int, thread_graphic
> >*
]’
/opt/hisi-linux/x86-arm/arm-himix200-linux/arm-linux-gnueabi/include/c++/6.3.0/bits/stl_tree.h:2196:64: required from ‘std::_Rb_tree
<_Key, _Val, _KeyOfValue, _Compare, _Alloc
>::iterator std::_Rb_tree
<_Key, _Val, _KeyOfValue, _Compare, _Alloc
>::_M_emplace_hint_unique
(std::_Rb_tree
<_Key, _Val, _KeyOfValue, _Compare, _Alloc
>::const_iterator, _Args
&& ...
) [with _Args
= {const std::piecewise_construct_t
&, std::tuple
<const int
&>, std::tuple
<>}; _Key
= int
; _Val
= std::pair
<const int, thread_graphic
>; _KeyOfValue
= std::_Select1st
<std::pair
<const int, thread_graphic
> >; _Compare
= std::less
<int
>; _Alloc
= std::allocator
<std::pair
<const int, thread_graphic
> >; std::_Rb_tree
<_Key, _Val, _KeyOfValue, _Compare, _Alloc
>::iterator
= std::_Rb_tree_iterator
<std::pair
<const int, thread_graphic
> >; std::_Rb_tree
<_Key, _Val, _KeyOfValue, _Compare, _Alloc
>::const_iterator
= std::_Rb_tree_const_iterator
<std::pair
<const int, thread_graphic
> >]’
/opt/hisi-linux/x86-arm/arm-himix200-linux/arm-linux-gnueabi/include/c++/6.3.0/bits/stl_map.h:483:8: required from ‘std::map
<_Key, _Tp, _Compare, _Alloc
>::mapped_type
& std::map
<_Key, _Tp, _Compare, _Alloc
>::operator
[](const key_type
&) [with _Key
= int
; _Tp
= thread_graphic
; _Compare
= std::less
<int
>; _Alloc
= std::allocator
<std::pair
<const int, thread_graphic
> >; std::map
<_Key, _Tp, _Compare, _Alloc
>::mapped_type
= thread_graphic
; std::map
<_Key, _Tp, _Compare, _Alloc
>::key_type
= int
]’
我特喵啥也看不懂,結果后來用了find和insert,一下就好了,具體原因沒深究,估計要看一下源碼才知道了,這個問題先記下吧
總結
以上是生活随笔為你收集整理的map中括号的坑的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。