-
passing HWND to STL map
Hi,
I’m trying to pass a HWND type to a STL map container.
I’m using like a void * to pass that parameter.
I’ve coded like this,
Code:
Void fun (HWND hOwner, LPCTSTR str, HWND hValue)
{
map<const void*, std::string, void *> m1;
m1.insert(make_pair(hOwner,str),hValue); //Line 2
}
I’m getting a compile time error ( Error Code C2664) in line 2.
Kindly guide me how to implement this.
-
>I’m getting a compile time error ( Error Code C2664) in line 2.
Great. And the error is?
>Kindly guide me how to implement this.
Well, you're calling the wrong function and any decent reference will show you how to fix it. I'm sure the error tells you this, but you neglected to post it, so the only way I know is by knowing std::map's member functions. You see, it's hard to answer questions without sufficient information. You simply lucked out and got a helper who knows exactly what your problem is at a glance. That's unlikely to be a regular occurrence.
-
passing HWND to STL map
Hi,
I didn't post the error message because, it had a very lengthy description.
So, hope the error number would be better to represent it.
And you are right that my explanations are not clear to help a person to understand the scenario.
My requirement is to store two values of type HWND and a string value in a map. The key should be a paired value of a HWND 1 and a string, the value type is HWND 2. I tried to do this using a void* pointer. But I got a compiler error about the improper conversion.
Could you kindly guide me how to do a type cast for HWND type to store it in STL map?
-
If you want the key to be a paired value of HWND and string, you should define the map as:
Code:
std::map<std::pair<HWND, std::string>, std::string>
You could also create your own struct to pair the key together instead of std::pair.
There is no need to typecast HWND to store it in a map. It will work just as it is.
To insert, you will need to use make_pair twice. Once to pair the HWND and string to form the key, and then again to pair that result with the string value.