The not declare issue occurs when hash_set is compiled in G ++.

Source: Internet
Author: User

I used the hash_set container when I wrote a program under Ubuntu today. There was a problem. Here I will record it. Let's talk about it. The hash _ * series, such as hash_map and hash_set, have been deprecated, c ++ 11 is replaced by unordered_map and unordered_set. However, I use g ++ 4.6.1 To warn that the C ++ 11 feature is experimental and seems to be fully supported by 4.8. So I switched to hash_set and wrote the following program:

#include <iostream>#include <string>#include 



Direct error: Error: 'hash _ set' was not declared in this scope

It is strange that the header file is included, and the original hash_set is included in the namespace _ gnu_cxx.

Using namespace _ gnu_cxx is compiled and jumped to hashtable. in the source code of H, the hasher function is shown as follows: Error: no match for call to '(const hasher {aka const _ gnu_cxx: Hash <STD :: basic_string <char >>}) (const key_type &)'

This problem should be due to the fact that the hash function does not support the string class. However, I did not know how to solve this problem, and I found it online for a long time, find a solution on the Internet, as shown in the following code:


#include <iostream>#include <string>#include Finally, it can run successfully. The added part is mainly to convert the string class to a char * pointer before it can be hashed.

PS: this is not a big problem. If you encounter it by accident, record it here.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.