template<typename OBJ, class HashKey, class EqKey, class CmpKey>class heap2 {public: heap2(); ~heap2(); void reset(); void add(OBJ val); void decreaseKey(OBJ val); bool isIn(OBJ val); OBJ remove(); void pop() { remove(); } OBJ top() { return _elts[0]; } OBJ find(OBJ val); bool empty(); unsigned size() { return _elts.size(); }// void verifyData();private: std::vector<OBJ> _elts; void heapifyUp(unsigned int index); void heapifyDown(unsigned int index); typedef __gnu_cxx::hash_map<OBJ, unsigned int, HashKey, EqKey > IndexTable; IndexTable table;};
This code snippet compiles just fine under Linux.
Pay attention to __gnu_cxx::hash_map
template<typename OBJ, class HashKey, class EqKey, class CmpKey>class heap2 {public: heap2(); ~heap2(); void reset(); void add(OBJ val); void decreaseKey(OBJ val); bool isIn(OBJ val); OBJ remove(); void pop() { remove(); } OBJ top() { return _elts[0]; } OBJ find(OBJ val); bool empty(); unsigned size() { return _elts.size(); }private: std::vector<OBJ> _elts; void heapifyUp(unsigned int index); void heapifyDown(unsigned int index); typedef stdext::hash_map<OBJ, unsigned int, HashKey, EqKey> IndexTable; IndexTable table;};
while this code snippet has trouble when being instantiated.
class SearchNode { public: SearchNode(double _fCost=0, double _gCost=0, uint32_t curr=0, uint32_t prev=0) : fCost(_fCost), gCost(_gCost), currNode(curr), prevNode(prev) { } SearchNode(uint32_t curr) : fCost(0), gCost(0), currNode(curr), prevNode(0) { } double fCost; double gCost; uint32_t currNode; uint32_t prevNode; }; struct SearchNodeEqual { bool operator()(const SearchNode& i1, const SearchNode &i2) { return i1.currNode == i2.currNode; } }; struct SearchNodeCompare { bool operator()(const SearchNode &i1, const SearchNode &i2) { if (fequal(i1.fCost, i2.fCost)) { return (fless(i1.gCost, i2.gCost)); } return (fgreater(i1.fCost, i2.fCost)); } }; struct SearchNodeHash { size_t operator()(const SearchNode& x) const { return (size_t)(x.currNode); } }; typedef heap2<GenericAStarUtil::SearchNode, GenericAStarUtil::SearchNodeHash, GenericAStarUtil::SearchNodeEqual, GenericAStarUtil::SearchNodeCompare> PQueue;
GenericAStarUtil::PQueue openQueue;
Error:
1>Compiling...1>GenericAStar.cpp1>d:\program files (x86)\microsoft visual studio 9.0\vc\include\hash_map(32) : error C2903: 'rebind' : symbol is neither a class template nor a function template1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\xhash(191) : see reference to class template instantiation 'stdext::_Hmap_traits<_Kty,_Ty,_Tr,_Alloc,_Mfl>' being compiled1> with1> [1> _Kty=GenericAStarUtil::SearchNode,1> _Ty=unsigned int,1> _Tr=GenericAStarUtil::SearchNodeHash,1> _Alloc=GenericAStarUtil::SearchNodeEqual,1> _Mfl=false1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\hash_map(88) : see reference to class template instantiation 'stdext::_Hash<_Traits>' being compiled1> with1> [1> _Traits=stdext::_Hmap_traits<GenericAStarUtil::SearchNode,unsigned int,GenericAStarUtil::SearchNodeHash,GenericAStarUtil::SearchNodeEqual,false>1> ]1> c:\users\garfield\documents\visual studio 2008\projects\mock pathfinding\mock pathfinding\util\heap2.h(29) : see reference to class template instantiation 'stdext::hash_map<_Kty,_Ty,_Tr,_Alloc>' being compiled1> with1> [1> _Kty=GenericAStarUtil::SearchNode,1> _Ty=unsigned int,1> _Tr=GenericAStarUtil::SearchNodeHash,1> _Alloc=GenericAStarUtil::SearchNodeEqual1> ]1> c:\users\garfield\documents\visual studio 2008\projects\mock pathfinding\mock pathfinding\util\genericastar.h(88) : see reference to class template instantiation 'heap2<OBJ,HashKey,EqKey,CmpKey>' being compiled1> with1> [1> OBJ=GenericAStarUtil::SearchNode,1> HashKey=GenericAStarUtil::SearchNodeHash,1> EqKey=GenericAStarUtil::SearchNodeEqual,1> CmpKey=GenericAStarUtil::SearchNodeCompare1> ]1>d:\program files (x86)\microsoft visual studio 9.0\vc\include\hash_map(32) : error C2039: 'rebind' : is not a member of 'GenericAStarUtil::SearchNodeEqual'1> c:\users\garfield\documents\visual studio 2008\projects\mock pathfinding\mock pathfinding\util\genericastar.h(27) : see declaration of 'GenericAStarUtil::SearchNodeEqual'
I understand that the declaration differs, but how come the Linux version compiles while the Windows version won't.
Anyone give that a fix, please?