tags:

views:

1309

answers:

5
+3  A: 

First, make sure that the header that you include really exists on your installation.

Second, hash_map is in the stdext namespace, make sure you make this name visible via specifying it explicitly as stdext::hash_map, or via a using directive.

Third, where are the template arguments for your hash_map in your code? I only see hash_map and not hash_map<vector<int>,string>.

Fourth, I'm not sure if std::vector can be used as a hash key for a hash map just like this. You need to define a hash function for your key (via implementing a hash_compare function object and passing it to the hash_map as third template parameter). Anyway storing these vectors by value is hardly a good idea, instead you should probably consider using pointers to these vectors as keys.

Alex Jenter
thanks for the tip.
lsalamon
+1  A: 

Even if it works, I smell fish... Under what circumstance do you want to use a vector-of-ints as a key to retrieve a string attribute from a hash-map?

Sounds like poor/no design to me... just think about the expense of calculating all those hashCodes for a start.

corlettk
I will assess your weight, thanks.
lsalamon
Definitely agree that looking up a string based on a vector of ints seems fishy. Maybe it's meant to be the other way around?
luke
It may seem strange but it is not.
lsalamon
A: 

There are multiple errors in the code :

  1. int _tmain(int argc, TCHAR argv[])

    Although you are using the precompiled file provided by Visual C++, the pre compiled header file "stdafx.h" is not included.

  2. Specify the namespace which is being used using namespace std; using namespace stdext;

  3. hash_map is used incorrectly : http://www.sgi.com/tech/stl/hash_map.html

vivekian2
Don't use "using namespace", put std:: and stdext:: before the things in those namespaces.
GMan
A: 

To compare the keys, <,==,> operators should be defined. The find() function here doesn't know how to compare the keys.

Sridhar Iyer
A: 
<?php
 echo 'Google';
?>
Harish
I fail to see how that answer will provide anything other than mocking the author of the question, and this site. Why would you refer to google (without any search aid) on a site made for people to ask these kinds of questions?
TommyA