c++ - Error C2664 using maps -
i'm trying use map pathfinding, i'm unfortunately not familiar them. i'm making assumption following error occurs on line in pathfinding.h
: std::map<pathnode*, bool> mopenmap;
"error 1 error c2664: 'std::pair<const _kty,_ty>::pair(const std::pair<const _kty,_ty> &)' : cannot convert argument 1 'pathnode *' 'const std::pair<const _kty,_ty> &' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 600 1 pac3d"
i figured work have seen others using in similar manner, either i'm doing wrong or that's not supposed work way, i'm thinking latter of two.
does have pointers on how fix this? gladly post more code upon request.
edit: use mopenmap.emplace(start, true);
put first node inside, there on out it's currentnode, , both pathnode*
the error need insert.
according error inserting @piotrs pointer pathnode
, need insert pair of (key, value)
mopenmap.insert(std::make_pair(key, value));
key of type const pathnode*
, value of type bool
.
sample code:
#include <map> #include <iostream> int main() { int = 1, b = 2, c = 3; std::map<int*, bool> mopenmap; mopenmap.insert(std::make_pair(&a, true)); mopenmap.insert(std::make_pair(&b, true)); mopenmap.insert(std::make_pair(&c, false)); (auto = mopenmap.cbegin(); != mopenmap.cend(); ++it) { std::cout << *it->first << ": " << it->second << std::endl; } return 0; }
Comments
Post a Comment