【发布时间】:2011-09-29 12:35:39
【问题描述】:
无法理解:g++ 编译器很生气:
lengths.insert(pair<Deux,long>(d,one));
在哪里
struct Deux {long big; long small};
map<Deux, long> lengths;
Deux d;
long one;
所以,g++ 说,我想念operator<。在为struct Deux 重载operator< 后,我看到了新的有趣,但同样的错误:
map <long, Node*>ArrayOfNodes;
map <long, Node*>::iterator it;
for (it=ArrayOfNodes[Root]->nodes.begin();it<ArrayOfNodes[Root]->nodes.end();++it)
cout<<it->first<<endl;
也用到了结构节点:
struct Node {
long name;
long guest;
map <long,Node*>nodes;
/*bool operator<(const Node& node)const{
if ((*this).name<node.name) return true;
if ((*this).name>node.name) return false;
return (*this).guest<(*this).guest;
}*/
错误是:
no match for operator< in it < ((Path*)this)->Path::ArrayOfNodes.
std::map<_Key, _Tp, _Compare, _Alloc>::operator[] [with _Key = long int, _Tp = Node*,
_Compare = std::less<long int>, _Alloc = std::allocator<std::pair<const long int, Node*> >]
(((const long int&)((const long int*)(&((Path*)this)->Path::Root))))->Node::nodes.std::map<_Key, _Tp, _Compare, _Alloc>::end
[with _Key = long int, _Tp = Node*, _Compare = std::less<long int>, _Alloc = std::allocator<std::pair<const long int, Node*> >]()
【问题讨论】:
-
什么是编译器错误信息?
-
为什么不更新您的问题,向我们展示实际代码和实际编译器错误消息?
-
抱歉,我的网络连接中断了。好的,谢谢,这个重载运算符的问题
-
@loldop:我们投入时间来猜测您的问题。您至少可以更新您的帖子,以便其他人可以从中学习。否则,stackoverflow 可能不适合您,而您更喜欢付费支持。