c++ map之insert问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zkybeck_ck/article/details/51568335

class B
{
public:
B(){m_b=0;}
B(int b){m_b = b;}
public:
int m_b;
};


int _tmain(int argc, _TCHAR* argv[])
{
map<int,B> mapB;
B b1(1);
B b2(12);
B b3(3);
mapB.insert(make_pair(1,b1));
mapB.insert(make_pair(2,b3));
mapB.insert(make_pair(2,b2));

map<int,B>::iterator it = mapB.find( 2 );
cout << it->second.m_b << endl;

}



在执行插入时,如果已经存在改键值,则不会进行插入,故上面输出的值仍然为b3的值,即3.

猜你喜欢

转载自blog.csdn.net/zkybeck_ck/article/details/51568335