'error C2888: 'std::hash' : symbol cannot ...

All,
I investiagted a lot but the answers I found don't help me out.
I'm migrating code from VS 2008 to 2010. The piece of code which
causes me problems is quiete simple but I don't find the solution:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace std
{
	template<>
	struct less<FDL::MessagePtr> : public binary_function<FDL::MessagePtr, FDL::MessagePtr, bool>
	{
		bool operator()(const FDL::MessagePtr& lhs, const FDL::MessagePtr& rhs)
		{
			return lhs->level < rhs->level;
		}
	};

	template<>
	struct equal_to<FDL::MessagePtr> : public binary_function<FDL::MessagePtr, FDL::MessagePtr, bool> 
	{
		bool operator()(const FDL::MessagePtr& lhs, const FDL::MessagePtr& rhs) const
		{
			return lhs->level == rhs->level;
		}
	};

	namespace tr1
		{
		template<>
		struct hash<FDL::MessagePtr> : public Unary_function<FDL::MessagePtr, size_t> 
		{
			size_t operator()(const FDL::MessagePtr& val) const
			{
				return val->level;
			}
		};
	 } // namespace tr1
} // namespace std 



With line
'struct hash<FDL::MessagePtr> : public Unary_function<FDL::MessagePtr, size_t> '
I get the error:
'error C2888: 'std::hash' : symbol cannot be defined within namespace 'tr1''.

If I delete 'namspace tr1' I get into troubles even more.

Any help much appreciated,
thx in advance
surplus


Last edited on
Why are you trying to add something into the std namesapce? I recommend that you instead create your own namespace and then properly scope those standard functions and classes.

By the way did you read the documentation for that error?

I read the docs.

The answer seems to be like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace std
{
	template<>
	struct less<FDL::MessagePtr> : public binary_function<FDL::MessagePtr, FDL::MessagePtr, bool>
	{
		bool operator()(const FDL::MessagePtr& lhs, const FDL::MessagePtr& rhs)
		{
			return lhs->level < rhs->level;
		}
	};

	template<>
	struct equal_to<FDL::MessagePtr> : public binary_function<FDL::MessagePtr, FDL::MessagePtr, bool> 
	{
		bool operator()(const FDL::MessagePtr& lhs, const FDL::MessagePtr& rhs) const
		{
			return lhs->level == rhs->level;
		}
	};

	//namespace tr1
		//{
		template<>
		struct hash<FDL::MessagePtr> : public Unary_function<FDL::MessagePtr, size_t> 
		{
			size_t operator()(const FDL::MessagePtr& val) const
			{
				return val->level;
			}
		};
	 //} // namespace tr1
} // namespace std  


"... hash is in namespace std in VS2010, as it's part of C++0x's Standard library, not std::tr1. "
No more errors during compilation.

/surplus
Last edited on
The solution is like this :

1
2
3
4
5
6
7
8
9
10
11
//namespace tr1
		//{
		template<>
		struct hash<FDL::MessagePtr> : public Unary_function<FDL::MessagePtr, size_t> 
		{
			size_t operator()(const FDL::MessagePtr& val) const
			{
				return val->level;
			}
		};
	// } // namespace tr1 


"... hash is in namespace std in VS2010, as it's part of C++0x's Standard library, not std::tr1. "
Topic archived. No new replies allowed.