2014-11-08 44 views
0

我正在收紧一些渲染代码,而不是将所有可渲染对象存储在普通的ol矢量中,我决定使用优先级队列(这样透明度等事情可以自动按优先级正确排列) 。然而,我无法让它与列表一起作为基础数据结构。我已经尝试过使用函子和超载运算符<。它抱怨:优先级队列与向量一起工作但不是列表

Error 8 error C2676: binary '-' : 'std::_List_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' does not define this operator or a conversion to a type acceptable to the predefined operator c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2425 1 ObjLoaded 
Error 4 error C2676: binary '-' : 'std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' does not define this operator or a conversion to a type acceptable to the predefined operator c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2331 1 ObjLoaded 
Error 7 error C2784: 'unknown-type std::operator -(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::_List_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2425 1 ObjLoaded 
Error 3 error C2784: 'unknown-type std::operator -(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2331 1 ObjLoaded 
Error 6 error C2784: 'unknown-type std::operator -(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::_List_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2425 1 ObjLoaded 
Error 2 error C2784: 'unknown-type std::operator -(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2331 1 ObjLoaded 
Error 5 error C2784: 'unknown-type std::operator -(std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'std::move_iterator<_RanIt> &' from 'std::_List_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2425 1 ObjLoaded 
Error 1 error C2784: 'unknown-type std::operator -(std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'std::move_iterator<_RanIt> &' from 'std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2331 1 ObjLoaded 

这是怎么了声明优先级队列:

priority_queue<IRenderable*, list<IRenderable*>> m_renderlist; 

与重载<运营商。如果我做一个简单的更改,一切都运行:

priority_queue<IRenderable*, vector<IRenderable*>> m_renderlist; 

任何想法为什么这里可能会发生?为了完整起见,这里是我的过载和函子:

bool IRenderable::operator<(const IRenderable* comp) 
{ 
    if (this->GetPriority() < comp->GetPriority()) 
     return true; 
    return false; 
} 

//class IRenderableComp 
//{ 
//public: 
// bool operator()(const IRenderable* first, const IRenderable* second) 
// { 
//  if (first->GetPriority() < second->GetPriority()) 
//   return true; 
//  return false; 
// } 
//}; 

不是超级重要的,因为我可以得到它与载体的工作,但这个小东西,我的错误,我想知道为什么。任何洞察力将不胜感激。感谢

回答

0

23.6.4/1随机访问迭代和支持操作front()push_back()pop_back()和任何序列容器可被用于实例化priority_queue

23.3.5.1/1list是支持双向迭代器序列容器......

重点煤矿。

+0

哦,哇,我觉得哑巴。我甚至查看了我的“C++标准库 - 教程和参考”副本,显然完全忽略了这一点。谢谢 – user3355098 2014-11-08 03:39:34