为什么我时不时会看到「珍惜生命,远离 C++」?

C语言  必备Linux命令和C语言基础
http://www.makeru.com.cn/video/2234_12010.html?s=148349
C语言  数据类型、常量、变量及运算符
http://www.makeru.com.cn/video/2234_12010.html?s=148349
C语言  输入输出专题
http://www.makeru.com.cn/video/2236_12027.html?s=148349
C语言  控制语句
http://www.makeru.com.cn/video/2236_12027.html?s=148349
C语言  数组和字符串
http://www.makeru.com.cn/video/2236_12027.html?s=148349
数据结构之链表精讲  线性表之单链表(上)

http://www.makeru.com.cn/video/12746_34512.html?s=148349

 

竟然没人举实例,我给一个吧……

1.#include"stdio.h"
2.#include"sparsepp-master/sparsepp.h"
3.int main()
4.{
5.	spp::sparse_hash_map<std::pair<int,int>,int> mp;
	6.mp.insert(std::make_pair(std::make_pair(1,1),1));
	7.return 0;
8.}

这个程序时使用sparsepp库提供的hash版map来存数据的例子,但他有一个错误:库中并没有给出为std::pair<int,int>产生hash值的算法,因此该程序不能工作。

理想情况下我们想要编译器这么提示我们:“亲爱的程序员,您的程序这里有错,错误原因和解决方法我都给你标注好了,么么嗒~~~”

具体错误提示大概长这样:

line 6:mp.insert(std::make_pair(std::make_pair(1,1),1));
                                ^^^^^^^^^^^^^^^^^^^ can't generate serialization

但实际上有点困难,一般编译器只会这么提示我们:“吔屎啦,这里这里这里这里这里这里我都看不懂,赶紧给老娘改!”

JAVA和javascript就喜欢这么干,错误提示大概长这样:

In file sparsepp-master/sparsepp.h:1483:42: XXXXXX
In file sparsepp-master/sparsepp.h:5069:77: XXXXXX
In file main.cpp:6:25: type cast failed
In file main.cpp:3:1: XXXXX

 

而混乱邪恶的C++是这样提示我们的:

 

In file included from main.cpp:2:0:
sparsepp-master/sparsepp.h: In instantiation of 'size_t spp::spp_hash<T>::op
erator()(const T&) const [with T = std::pair<int, int>; size_t = long long u
nsigned int]':
sparsepp-master/sparsepp.h:1483:42:   required from 'size_t spp::sparsehash_
internal::sh_hashtable_settings<Key, HashFunc, SizeType, HT_MIN_BUCKETS>::ha
sh(const key_type&) const [with Key = std::pair<int, int>; HashFunc = spp::s
pp_hash<std::pair<int, int> >; SizeType = long long unsigned int; int HT_MIN
_BUCKETS = 4; size_t = long long unsigned int; spp::sparsehash_internal::sh_
hashtable_settings<Key, HashFunc, SizeType, HT_MIN_BUCKETS>::key_type = std:
:pair<int, int>]'
sparsepp-master/sparsepp.h:4729:31:   required from 'size_t spp::sparse_hash
table<Value, Key, HashFcn, ExtractKey, SetKey, EqualKey, Alloc>::hash(const 
key_type&) const [with Value = std::pair<std::pair<int, int>, int>; Key = st
d::pair<int, int>; HashFcn = spp::spp_hash<std::pair<int, int> >; ExtractKey
 = spp::sparse_hash_map<std::pair<int, int>, int>::SelectKey; SetKey = spp::
sparse_hash_map<std::pair<int, int>, int>::SetKey; EqualKey = std::equal_to<
std::pair<int, int> >; Alloc = spp::libc_allocator_with_realloc<std::pair<co
nst std::pair<int, int>, int> >; size_t = long long unsigned int; spp::spars
e_hashtable<Value, Key, HashFcn, ExtractKey, SetKey, EqualKey, Alloc>::key_t
ype = std::pair<int, int>]'
sparsepp-master/sparsepp.h:4242:33:   required from 'spp::sparse_hashtable<V
alue, Key, HashFcn, ExtractKey, SetKey, EqualKey, Alloc>::Position spp::spar
se_hashtable<Value, Key, HashFcn, ExtractKey, SetKey, EqualKey, Alloc>::_fin
d_position(const key_type&) const [with Value = std::pair<std::pair<int, int
>, int>; Key = std::pair<int, int>; HashFcn = spp::spp_hash<std::pair<int, i
nt> >; ExtractKey = spp::sparse_hash_map<std::pair<int, int>, int>::SelectKe
y; SetKey = spp::sparse_hash_map<std::pair<int, int>, int>::SetKey; EqualKey
 = std::equal_to<std::pair<int, int> >; Alloc = spp::libc_allocator_with_rea
lloc<std::pair<const std::pair<int, int>, int> >; spp::sparse_hashtable<Valu
e, Key, HashFcn, ExtractKey, SetKey, EqualKey, Alloc>::key_type = std::pair<
int, int>]'
sparsepp-master/sparsepp.h:4401:38:   required from 'std::pair<typename spp:
:sparsetable<Value, typename Alloc::rebind<Value>::other>::ne_iterator, bool
> spp::sparse_hashtable<Value, Key, HashFcn, ExtractKey, SetKey, EqualKey, A
lloc>::_insert_noresize(T&) [with T = const std::pair<const std::pair<int, i
nt>, int>; Value = std::pair<std::pair<int, int>, int>; Key = std::pair<int,
 int>; HashFcn = spp::spp_hash<std::pair<int, int> >; ExtractKey = spp::spar
se_hash_map<std::pair<int, int>, int>::SelectKey; SetKey = spp::sparse_hash_
map<std::pair<int, int>, int>::SetKey; EqualKey = std::equal_to<std::pair<in
t, int> >; Alloc = spp::libc_allocator_with_realloc<std::pair<const std::pai
r<int, int>, int> >; typename spp::sparsetable<Value, typename Alloc::rebind
<Value>::other>::ne_iterator = spp::Two_d_iterator<std::pair<std::pair<int, 
int>, int>, spp::sparsegroup<std::pair<std::pair<int, int>, int>, spp::libc_
allocator_with_realloc<std::pair<std::pair<int, int>, int> > >*, std::pair<c
onst std::pair<int, int>, int>*, std::bidirectional_iterator_tag>]'
sparsepp-master/sparsepp.h:4451:36:   required from 'std::pair<typename spp:
:sparsetable<Value, typename Alloc::rebind<Value>::other>::ne_iterator, bool
> spp::sparse_hashtable<Value, Key, HashFcn, ExtractKey, SetKey, EqualKey, A
lloc>::insert(spp::sparse_hashtable<Value, Key, HashFcn, ExtractKey, SetKey,
 EqualKey, Alloc>::const_reference) [with Value = std::pair<std::pair<int, i
nt>, int>; Key = std::pair<int, int>; HashFcn = spp::spp_hash<std::pair<int,
 int> >; ExtractKey = spp::sparse_hash_map<std::pair<int, int>, int>::Select
Key; SetKey = spp::sparse_hash_map<std::pair<int, int>, int>::SetKey; EqualK
ey = std::equal_to<std::pair<int, int> >; Alloc = spp::libc_allocator_with_r
ealloc<std::pair<const std::pair<int, int>, int> >; typename spp::sparsetabl
e<Value, typename Alloc::rebind<Value>::other>::ne_iterator = spp::Two_d_ite
rator<std::pair<std::pair<int, int>, int>, spp::sparsegroup<std::pair<std::p
air<int, int>, int>, spp::libc_allocator_with_realloc<std::pair<std::pair<in
t, int>, int> > >*, std::pair<const std::pair<int, int>, int>*, std::bidirec
tional_iterator_tag>; spp::sparse_hashtable<Value, Key, HashFcn, ExtractKey,
 SetKey, EqualKey, Alloc>::const_reference = const std::pair<const std::pair
<int, int>, int>&; spp::sparse_hashtable<Value, Key, HashFcn, ExtractKey, Se
tKey, EqualKey, Alloc>::value_type = std::pair<const std::pair<int, int>, in
t>]'
sparsepp-master/sparsepp.h:5069:77:   required from 'std::pair<typename spp:
:sparse_hashtable<std::pair<typename spp::remove_const<Key>::type, T>, Key, 
HashFcn, spp::sparse_hash_map<Key, T, HashFcn, EqualKey, Alloc>::SelectKey, 
spp::sparse_hash_map<Key, T, HashFcn, EqualKey, Alloc>::SetKey, EqualKey, Al
loc>::iterator, bool> spp::sparse_hash_map<Key, T, HashFcn, EqualKey, Alloc>
::insert(const value_type&) [with Key = std::pair<int, int>; T = int; HashFc
n = spp::spp_hash<std::pair<int, int> >; EqualKey = std::equal_to<std::pair<
int, int> >; Alloc = spp::libc_allocator_with_realloc<std::pair<const std::p
air<int, int>, int> >; typename spp::sparse_hashtable<std::pair<typename spp
::remove_const<Key>::type, T>, Key, HashFcn, spp::sparse_hash_map<Key, T, Ha
shFcn, EqualKey, Alloc>::SelectKey, spp::sparse_hash_map<Key, T, HashFcn, Eq
ualKey, Alloc>::SetKey, EqualKey, Alloc>::iterator = spp::Two_d_iterator<std
::pair<std::pair<int, int>, int>, spp::sparsegroup<std::pair<std::pair<int, 
int>, int>, spp::libc_allocator_with_realloc<std::pair<std::pair<int, int>, 
int> > >*, std::pair<const std::pair<int, int>, int>*, std::bidirectional_it
erator_tag>; spp::sparse_hash_map<Key, T, HashFcn, EqualKey, Alloc>::value_t
ype = std::pair<const std::pair<int, int>, int>]'
main.cpp:6:49:   required from here
sparsepp-master/sparsepp.h:943:27: error: use of deleted function 'std::hash
<std::pair<int, int> >::hash()'
         SPP_HASH_CLASS<T> hasher;
                           ^~~~~~
In file included from E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64
/lib/gcc/x86_64-w64-mingw32/6.3.0/include/c++/bits/basic_string.h:5628:0,
                 from E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64
/lib/gcc/x86_64-w64-mingw32/6.3.0/include/c++/string:52,
                 from sparsepp-master/sparsepp.h:839,
                 from main.cpp:2:
E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/lib/gcc/x86_64-w64-mi
ngw32/6.3.0/include/c++/bits/functional_hash.h:85:12: note: 'std::hash<std::
pair<int, int> >::hash()' is implicitly deleted because the default definiti
on would be ill-formed:
     struct hash : __hash_enum<_Tp>
            ^~~~
E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/lib/gcc/x86_64-w64-mi
ngw32/6.3.0/include/c++/bits/functional_hash.h:85:12: error: no matching fun
ction for call to 'std::__hash_enum<std::pair<int, int>, false>::__hash_enum
()'
E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/lib/gcc/x86_64-w64-mi
ngw32/6.3.0/include/c++/bits/functional_hash.h:66:7: note: candidate: std::_
_hash_enum<_Tp, <anonymous> >::__hash_enum(std::__hash_enum<_Tp, <anonymous>
 >&&) [with _Tp = std::pair<int, int>; bool <anonymous> = false]
       __hash_enum(__hash_enum&&);
       ^~~~~~~~~~~
E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/lib/gcc/x86_64-w64-mi
ngw32/6.3.0/include/c++/bits/functional_hash.h:66:7: note:   candidate expec
ts 1 argument, 0 provided
E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/lib/gcc/x86_64-w64-mi
ngw32/6.3.0/include/c++/bits/functional_hash.h:85:12: error: 'std::__hash_en
um<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::pair<int, int>; bool 
<anonymous> = false]' is private within this context
     struct hash : __hash_enum<_Tp>
            ^~~~
E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/lib/gcc/x86_64-w64-min
gw32/6.3.0/include/c++/bits/functional_hash.h:67:7: note: declared private he
re
       ~__hash_enum();
       ^
In file included from main.cpp:2:0:
sparsepp-master/sparsepp.h:943:27: error: use of deleted function 'std::hash<
std::pair<int, int> >::~hash()'
         SPP_HASH_CLASS<T> hasher;
                           ^~~~~~
In file included from E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/
lib/gcc/x86_64-w64-mingw32/6.3.0/include/c++/bits/basic_string.h:5628:0,
                 from E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/
lib/gcc/x86_64-w64-mingw32/6.3.0/include/c++/string:52,
                 from sparsepp-master/sparsepp.h:839,
                 from main.cpp:2:
E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/lib/gcc/x86_64-w64-min
gw32/6.3.0/include/c++/bits/functional_hash.h:85:12: note: 'std::hash<std::pa
ir<int, int> >::~hash()' is implicitly deleted because the default definition
 would be ill-formed:
     struct hash : __hash_enum<_Tp>
            ^~~~
E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/lib/gcc/x86_64-w64-min
gw32/6.3.0/include/c++/bits/functional_hash.h:85:12: error: 'std::__hash_enum
<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::pair<int, int>; bool <an
onymous> = false]' is private within this context
E:/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/lib/gcc/x86_64-w64-min
gw32/6.3.0/include/c++/bits/functional_hash.h:67:7: note: declared private he
re
       ~__hash_enum();
       ^
In file included from main.cpp:2:0:
sparsepp-master/sparsepp.h:944:22: error: no match for call to '(std::hash<st
d::pair<int, int> >) (const std::pair<int, int>&)'
         return hasher(__v);
                ~~~~~~^~~~~

C++:”你叼是吧?你调啊?你调啊?怎么不调了?刚才不是很跳么?哎我就不明白了,你现在嘴长哪去了?刚才blablablabla不是很能说嘛?你现在倒是说说看程序错哪里了啊?“

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值