c++ - using for loop to instantiate a map -
i trying use loop add key-value map:
std::map< std::pair<const int &, const int &>, double> mymap; for(int i=0;i<3;i++){ mymap[std::make_pair(i,i+1)]=0.1*i; } std::cout<<mymap.size()<<std::endl; i don't understand why size of mymap 1. expect 3 size. did make mistake? lot.
use std::pair<int, int> instead of std::pair<const int&, const int&>.
const int& reference (as opposed value). since i has same location each time, , it's possible same temporary location used i+1, means using same pair each time.
Comments
Post a Comment