65,208
社区成员
发帖
与我相关
我的任务
分享
#include <string>
#include <map>
#include <iostream>
using namespace std;
class A
{
public:
A() {
cout << "A constructor." << endl;
}
A(const A &other) {
cout << "A copy constructor" << endl;
}
A& operator=(const A &other) {
if (&other == this)
return *this;
cout << "A operator = " << endl;
return *this;
}
~A() {
cout << "A deconstructor" << endl;
}
};
int main(int argc, char** argv)
{
map<int, A> m_map;
{
cout << "---------------1-------------" << endl;
A a;
m_map.insert(make_pair(1, a));
cout << "---------------1-------------" << endl;
}
{
cout << "---------------2-------------" << endl;
A a;
m_map[2] = a;
cout << "---------------2-------------" << endl;
}
cout << "---------------end-------------" << endl;
return 0;
}
学习了,mark