0

i am using a map with key as 'tm structure' defined in time.h now when i'm using statement it=HashTime.find(tm structure object); where it is the iterator then i am getting error like:

no match for 'operator=' in '((const CTime*)this)->CTime::HashTime.std::map<_Key, _Tp, _Compare, _Alloc>::find [with _Key = tm, _Tp = long int, _Compare = CTime::compare, _Alloc = std::allocator<std::pair<const tm, long int> >, std::map<_Key, _Tp, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<const tm, long int> >, key_type = tm](((const std::map<tm, long int, CTime::compare>::key_type&)((const std::map<tm, long int, CTime::compare>::key_type*)m_ntmDate))) = m_datesec'

12
  • what's the type of it and HashTime? and does it work if you use auto it = HashTime.find(...);? Commented Feb 3, 2012 at 6:43
  • can you post a minimal example? Commented Feb 3, 2012 at 8:25
  • Actually i am a bit new to c++ so this what i have coded Commented Feb 3, 2012 at 9:55
  • Actually i am a bit new to c++ so this what i have coded Commented Feb 3, 2012 at 9:55
  • 1
    Could you please edit your post and add your code? Commented Feb 3, 2012 at 10:09

1 Answer 1

1

This may help you:

#include <iostream> #include <map> struct valueInfo { int value1; int value2; int value3; valueInfo(const int A,const int B,const int C) : value1(A),value2(B),value3(C) {} }; class valueComp { public: bool operator()(const valueInfo& A, const valueInfo& B) const { return A.value2<B.value2; } }; typedef std::map<valueInfo,double,valueComp> MapCTYPE; int main() { MapCTYPE TMap; valueInfo B(1,2,3); valueInfo C(3,3,4); TMap.insert(MapCTYPE::value_type(B,4.5)); TMap.insert(MapCTYPE::value_type(C,8.4)); MapCTYPE::iterator vc=TMap.find(MapCTYPE::key_type(1,2,8)); if (vc!=TMap.end()) { std::cout<<"Success:"<<vc->second<<std::endl; } } 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks alot :) your post has solved my operator overloading errors.This is what the i have written : void MakeTime( struct tm &trf) { it =HashTime.find(trf); if( it == HashTime.end()) { m_datesec= mktime (&trf); HashTime[trf]= m_datesec; } else { HashTime.find(trf) ; } } private: map<struct tm,long int,valueComp> HashTime; map<struct tm,long int,valueComp>::iterator it; long int m_datesec; }; but i am getting error:no matching function for call to'Time::MakeTime(tm*)
and i am calling the MakeTime function in other header file with strptime (strDate.c_str (), strFormat.c_str (), &m_tmDate); struct tm trf= m_tmDate; cobj.MakeTime(&trf); where m_tmDate is another tm structure having some values set for each of its variable.
valueComp is the class with bool operator()(const tm &A,const tm &B) const and cobj is object of Time class..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.