I'm new to std::map
, started using it only recently.
I'm facing a compilation issue with one of these mappings.
I have a custom structure, and am trying to create a mapping of a CString
, with objects of that structure type.
Unfortunately, I'm facing issues
Error 3 error C2664: 'std::pair<_Ty1,_Ty2>::pair(const std::pair<_Ty1,_Ty2> &)' : cannot convert parameter 1 from 'ItemInfo *' to 'const std::pair<_Ty1,_Ty2> &'
ItemInfo
is the structure, to which I'm trying to define a mapping using a CString
.
This is how I define the mapping..
struct ItemInfo
{<some code>}
class XXXX
{
std::map<CString, ItemInfo> myMap;
}
I'm not sure how exactly to solve this, or what I should be looking at.
If someone could tell me what this error is, and how I can solve it, it would be appreciated, thanks.
EDIT
OK - I searched a lot, but still couldn't see the error in my insert()
function. This is what I use:
mAlarmListMpa.insert(tempIterator /*the iterator over the map */, std::pair<CString, ItemInfo>(tagname , info));
EDIT Bit more information from the Output :
`
c:\\program files (x86)\\microsoft visual studio 10.0\\vc\\include\\xmemory(208): error C2664: 'std::pair<_Ty1,_Ty2>::pair(const std::pair<_Ty1,_Ty2> &)' : cannot convert parameter 1 from 'ItemInfo' to 'const std::pair<_Ty1,_Ty2> &' 1> with 1> [ 1> _Ty1=const CString, 1> _Ty2=ItemInfo 1> ] 1> Reason: cannot convert from 'ItemInfo' to 'const std::pair<_Ty1,_Ty2>' 1> with 1> [ 1> _Ty1=const CString, 1> _Ty2=ItemInfo 1> ] 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called `
Some code you're not showing us is trying to pass a pointer to ItemInfo
where it should be passing a key-value pair, presumably std::pair<CString, ItemInfo>
. The full error message should show you which line of code is doing that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.