珍爱生命远离c++就是这么来的

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>::operator()(const T&) const [with T = std::pair<int, int>; size_t = long long unsigned int]':

sparsepp-master/sparsepp.h:1483:42:  required from 'size_t spp::sparsehash_internal::sh_hashtable_settings<Key, HashFunc, SizeType, HT_MIN_BUCKETS>::hash(const key_type&) const [with Key = std::pair<int, int>; HashFunc = spp::spp_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_hashtable<Value, Key, HashFcn, ExtractKey, SetKey, EqualKey, Alloc>::hash(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, 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<const std::pair<int, int>, int> >; size_t = long long unsigned int; spp::sparse_hashtable<Value, Key, HashFcn, ExtractKey, SetKey, EqualKey, Alloc>::key_type = std::pair<int, int>]'

sparsepp-master/sparsepp.h:4242:33:  required from 'spp::sparse_hashtable<Value, Key, HashFcn, ExtractKey, SetKey, EqualKey, Alloc>::Position spp::sparse_hashtable<Value, Key, HashFcn, ExtractKey, SetKey, EqualKey, Alloc>::_find_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, 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<const std::pair<int, int>, int> >; spp::sparse_hashtable<Value, 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, Alloc>::_insert_noresize(T&) [with T = const std::pair<const std::pair<int, int>, int>; Value = std::pair<std::pair<int, int>, int>; Key = std::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<const std::pair<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<const 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, Alloc>::insert(spp::sparse_hashtable<Value, Key, HashFcn, ExtractKey, SetKey, EqualKey, Alloc>::const_reference) [with Value = std::pair<std::pair<int, int>, int>; Key = std::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<const std::pair<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<const std::pair<int, int>, int>*, std::bidirectional_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, SetKey, EqualKey, Alloc>::value_type = std::pair<const std::pair<int, int>, int>]'

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, Alloc>::iterator, bool> spp::sparse_hash_map<Key, T, HashFcn, EqualKey, Alloc>::insert(const value_type&) [with Key = std::pair<int, int>; T = int; HashFcn = 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::pair<int, int>, int> >; 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, 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_iterator_tag>; spp::sparse_hash_map<Key, T, HashFcn, EqualKey, Alloc>::value_type = 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-mingw32/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 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-mingw32/6.3.0/include/c++/bits/functional_hash.h:85:12: error: no matching function 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-mingw32/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-mingw32/6.3.0/include/c++/bits/functional_hash.h:66:7: note:  candidate expects 1 argument, 0 provided

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/functional_hash.h:85:12: error: 'std::__hash_enum<_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-mingw32/6.3.0/include/c++/bits/functional_hash.h:67:7: note: declared private here

      ~__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-mingw32/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 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-mingw32/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 <anonymous> = 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-mingw32/6.3.0/include/c++/bits/functional_hash.h:67:7: note: declared private here

      ~__hash_enum();

      ^

In file included from main.cpp:2:0:

sparsepp-master/sparsepp.h:944:22: error: no match for call to '(std::hash<std::pair<int, int> >) (const std::pair<int, int>&)'

        return hasher(__v);

                ~~~~~~^~~~~

☻☺这只是一段代码报错时候弹出的提示,当你想像一下一句话报错就能出现这么长的代码,当一个程序出现问题的时候,你找个错误都得找半天,所以大部分人都会选择修复bug然后就出现了更多的bug。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,530评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,403评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,120评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,770评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,758评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,649评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,021评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,675评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,931评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,751评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,410评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,004评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,969评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,042评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,493评论 2 343

推荐阅读更多精彩内容