// 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
这里出现了没有合适的默认构造函数可用
最新推荐文章于 2024-07-10 18:33:40 发布
这篇博客探讨了C++中遇到的没有合适默认构造函数可用的问题。示例展示了如何创建并插入`Emplyee`类的对象到`map`容器中,强调了在插入时需要提供完整构造参数的重要性。
摘要由CSDN通过智能技术生成