2013-02-07 66 views
0

我碰到一個問題讓我生氣。我已經使用跟隨着計時器進入結構實現定時器:編譯問題與VS2010和boost :: posix_time

typedef std::multimap<boost::posix_time::ptime, events::ITimeout*> TEntryMap; 
TEntryMap entries_; 

和我插入元素融入多重映射有:

boost::posix_time::ptime tTimeout = boost::posix_time::microsec_clock::local_time() + boost::posix_time::milliseconds(timeout); 
entries_.insert(std::make_pair(tTimeout, ptr)); // ptr is the events::ITimeout object 

,並在一個轉換單元(CPP文件),它完美的作品。不過,現在我需要這個功能移動到另一個CPP文件,現在我得到一個編譯錯誤:

1>Build started 2013-02-07 15:38:18. 
1>ClCompile: 
1> EventDispatcher.cpp 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(260): error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const boost::posix_time::ptime' (or there is no acceptable conversion) 
1>   ....\boost\boost\date_time\posix_time\ptime.hpp(57): could be 'boost::posix_time::ptime &boost::posix_time::ptime::operator =(const boost::posix_time::ptime &)' 
1>   while trying to match the argument list '(const boost::posix_time::ptime, const boost::posix_time::ptime)' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(259) : while compiling class template member function 'std::pair<_Ty1,_Ty2> &std::pair<_Ty1,_Ty2>::operator =(std::pair<_Ty1,_Ty2> &&)' 
1>   with 
1>   [ 
1>    _Ty1=const boost::posix_time::ptime, 
1>    _Ty2=events::ITimeout * 
1>   ] 
1>   ....\eventdispatcher.cpp(72) : see reference to class template instantiation 'std::pair<_Ty1,_Ty2>' being compiled 
1>   with 
1>   [ 
1>    _Ty1=const boost::posix_time::ptime, 
1>    _Ty2=events::ITimeout * 
1>   ] 
1> 

我無能以及與此掙扎了2小時。我看到工作實施和非工作實施之間沒有區別。相同的構造,相同的多重地圖,相同的一切! ;(

回答

0

我找到了問題的原因,它聞起來像一個VS2010 C++編譯器錯誤(當使用std :: remove_if時)在稍後使用該構造的類的函數實現中,我嘗試刪除元素在與地圖:

void removeEntry(events::ITimeout* p) 
{ 
    std::remove_if(entries_.begin(), entries_.end(), 
     [&](TEntryMap::value_type& entry)->bool 
     { 
      return (entry.second == p); 
     } 
    ); 
} 

改變這種代碼:。

void removeEntry(events::ITimeout* p) 
{ 
    TEntryMap::iterator it = std::find_if(entries_.begin(), entries_.end(), 
     [&](TEntryMap::value_type& entry)->bool 
     { 
      return (entry.second == p); 
     } 
    ); 
    if (it != entries_.end()) entries_.erase(it); 
} 

使得插入代碼的工作去圖請注意,即使我使用基於結構謂詞,而不是一個lambda封閉的,它仍然不能使用std :: remove_if ...