Archived

This topic is now archived and is closed to further replies.

Ziphnor

Argghh.. hash_map problems again

Recommended Posts

Some time ago i had a problem with the hashing method used by hash_map on std::string''s, but someone here was nice enough to suggest defining this:
  
size_t std::hash_compare<std::string>::operator ()(const std::string& val) const
{	
	size_t keyVal = 0;	
	for(size_t i = 0, l = val.size(); i < l; ++i)	
	{		
		keyVal += val[i];
	}	
	ldiv_t div = ldiv((long)keyVal, 127773);	
	div.rem = 16807 * div.rem - 2836 * div.quot;	
	if(div.rem < 0)	
	{		
		div.rem += 2147483647;	
	}	
	return div.rem;
}
  
This worked just fine. But suddenly, almost out of the blue im getting this error regarding the above:
d:\test\test\tets\SettingsParser.cpp(12): error C2511: ''size_t std::hash_compare<_Kty,_Pr>::operator ()(const std::string &) const'' : overloaded member function not found in ''std::hash_compare<_Kty,_Pr>''
        with
        [
            _Kty=std::string,
            _Pr=std::less
        ]
        and
        [
            _Kty=std::string,
            _Pr=std::less
        ]
 
Should i on the other hand just remove the hash method defined above, i get these errors:
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xhash(217): error C2064: term does not evaluate to a function
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xhash(217): error C2660: ''std::hash_compare,class std::allocator >,struct std::less,class std::allocator > > >::operator`()'''' : function does not take 1 parameters
 
This error comes even just from this code(removed the rest of the code to narrow down the cause of this):
  
#include <string>
#include <hash_map>
using namespace std;

static hash_map<string, string> settings;

void changeSetting(string setting, string value)
{
	settings[setting] = value;
}
  
I really dont understand this, i even tried going back to an older build of my project which i *KNOW* worked, and i can link it and run it, but if i *rebuild* it i get these errors.... ARGGHHH.... To make things even worse ive caught a terrible cold, so now im sitting here red-eyed sniffling over a project that wont compile ;(

Share this post


Link to post
Share on other sites