这里出现了没有合适的默认构造函数可用

// k.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include 
#include 
#include 
#include 
#include

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 mapEmplyee;

	Emplyee emp1("zz", 4);
	Emplyee emp2("hh", 5);
	Emplyee emp3("oo", 1);

	

	mapEmplyee.insert(pair(1, emp1));
	//或者通过value_type类型实现数据的插入
	mapEmplyee.insert(map::value_type(2,emp2));
	//或者直接插入数据,将(1983, emp1)插入
	mapEmplyee[1983] = emp3;

	//找到对应的键
	for (map::iterator it = mapEmplyee.begin(); it != mapEmplyee.end(); ++it)
	{
		cout<<"当前员工号是:"<first<second.GetName()<second.GetSalary()<

你可能感兴趣的:(小技巧)