c++ - overloading of < operator not called when using struct as key in map? -


i have understood have write operator overloading function < operator when have using key struct since map uses strict week ordering has compare before inserting in map.

hope understanding correct reading here.

consider following snippet

  struct node     {        int a;            };       // 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 called         return 0;     } 

and issue operator overloading function not called?

edit:

from answer below, after adding 1 more pair container operator overloading called. why called 3 times specifically, compared here?

when map empty, comparator not need invoked because there nothing compare against to.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -