Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Beginner
Dec 1, 1999

STL and User-Defined Classes

Question:
I'm new to the Standard Template Library. How do I incorporate a user-defined class into a hash_map? What functions do I need to overload? I get compiler errors when I try to insert into my hash_map for even the simplest of classes.

Answer:
Hash_map is not part of the Standard Template Library, at least officially. Hashed containers were presented to the C++ standardization committee too late, so the committee did not have sufficient time to include them in the C++ Standard.

Nevertheless, several vendors now offer proprietary hashed containers as an extension to Standard. However, these extensions are not compatible, nor is there any guarantee that they will be standardized in the future.

You didn't post the code that causes compilation errors or the error messages that you received, so I cannot give a specific answer. However, you should check the interaction of namespaces and the hash_map (i.e., is hash_map defined in the namespace STD or perhaps another namespace?).

In addition, make sure that your classes define appropriate default ctor, copy ctor, assignment operator, and destructor. Failing to do so is the most fertile source of compilation errors when using STL containers.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap