C++ (Qt)struct MyPtr { MyPtr( MyStruct * ptr = 0 ) : MPtr(ptr) {} bool operator < ( const MyPtr & sec ) const { if (!mPtr) return sec.mPtr != 0; // указатели могут быть NULL if (!sec.mPtr) return false; return *mPtr < *sec.mPtr; } MyStruct * mPtr;};
C++ (Qt)std::map <MyStruct *, int> theMap;
C++ (Qt)template <class T>class pointer_wrapper{public: pointer_wrapper(const T * p) : ptr(p) {} template <class R> friend bool operator<(const pointer_wrapper<R> &, const pointer_wrapper<R>&); private: const T * ptr;}; template <class R>bool operator<(const pointer_wrapper<R> & x, const pointer_wrapper<R> & y){ return *(x.ptr) < *(y.ptr);} std::map <pointer_wrapper<MyStruct> , int> theMap;
C++ (Qt)MyStruct * myStruct;theMap[myStruct] = 1;... theMap[pointer_wrapper(myStruct)] = 1;...