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

这篇博客探讨了C++中遇到的没有合适默认构造函数可用的问题。示例展示了如何创建并插入`Emplyee`类的对象到`map`容器中,强调了在插入时需要提供完整构造参数的重要性。
摘要由CSDN通过智能技术生成
// 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 = mapEmply
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值