// k.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <tuple>
#include <vector>
#include <string>
#include<map>
using namespace std;
class Emplyee
{
public:
Emplyee(string strName, int nYear)
{
m_strName = strName;
m_nYears = nYear;
}
public:
int GetSalary()
{
return m_nYears*1000;
}
string GetName()
{
return m_strName;
}
protected:
int m_nYears;
string m_strName;
};
int _tmain(int argc, _TCHAR* argv[])
{
map<int, Emplyee> mapEmplyee;
Emplyee emp1("zz", 4);
Emplyee emp2("hh", 5);
Emplyee emp3("oo", 1);
mapEmplyee.insert(pair<int, Emplyee>(1, emp1));
//或者通过value_type类型实现数据的插入
mapEmplyee.insert(map<int, Emplyee>::value_type(2,emp2));
//或者直接插入数据,将(1983, emp1)插入
mapEmplyee[1983] = emp3;
//找到对应的键
for (map<int, Emplyee>::iterator it = mapEmplyee.begin(); it != mapEmplyee.end(); ++it)
{
cout<<"当前员工号是:"<<it->first<<endl;
cout<<"姓名:"<<it->second.GetName()<<endl;
cout<<"工资:"<<it->second.GetSalary()<<endl;
}
return 0;
}
这里出现了没有合适的默认构造函数可用
最新推荐文章于 2025-01-10 14:14:05 发布