VIN*_*TIC 2 c++ operator-overloading map
我已经明白,当我们使用key作为struct时,我们必须为<operator编写运算符重载函数,因为map在插入map之前使用了必须比较的严格周序.
希望我的理解是正确的,请从这里阅读.
请考虑以下代码段
struct Node
{
int a;
};
// This is not called
bool operator< (const Node &p_node1,const Node &p_node2)
{
printf("\nCALLED OPERATOR OVERLOADING");
return true;
}
int main()
{
using namespace std;
map<Node,int> my_map;
Node n1;
n1.a=55;
my_map[n1]=2; // operator overloading should be called
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题是运营商重载功能没有被调用?
编辑:
从下面的答案中,在将另外一对添加到容器运算符后,调用重载.但是为什么它被专门召唤三次,这里有什么比较呢?
| 归档时间: |
|
| 查看次数: |
197 次 |
| 最近记录: |