c_str() causing difficulty

I have a function that is giving me a LNK1120 error. I am using visual studio and including <string>. Any ideas?

1
2
3
4
5
6
7
8
int hash(string temp)
{
	const char* key = temp.c_str();
	int sum;
	for (sum = 0; *key != 0; key++)
		sum += (unsigned char)*key;
	return sum % 16;
}
Error message.
I gather you didn't use "std::string temp" etc.

1
2
3
4
5
6
7
8
int hash(std::string temp)
{
	const char* key = temp.c_str();
	int sum;
	for (sum = 0; *key != 0; key++)
		sum += (unsigned char)*key;
	return sum % 16;
}


Should work fine. Your problem would be somewhere else if this doesn't fix it.
yes you probably havent used std::string.
declare that after including your header files and that should solve your linker error.
All of that would lead to compile-time errors, not link-time errors.

OP needs to post the actual linker error.
Topic archived. No new replies allowed.