c++map嵌套map

头文件

#ifndef __AOI_H__
#define __AOI_H__
#include 
#include 
using namespace std;

class A {
public:
	void AddSkill(int useID, int skillID);
private:
	struct Info
	{
		map skillInfo;
	};
	map useSkill;
};
#endif

cpp文件

#include "Aoi.h"
#include 
#include 
using namespace std;

void A::AddSkill(int useID, int skillID)
{
	auto it = this->useSkill.find(useID);
	if (it != this->useSkill.end())
	{
		auto iter = (*it).second.skillInfo.find(skillID);
		if (iter != (*it).second.skillInfo.end())
		{
			iter->second++;
		}
		else
		{
			it->second.skillInfo.insert(make_pair(skillID, 1));
		}

	}
	else
	{
		Info item;
		item.skillInfo.insert(make_pair(skillID, 1));
		this->useSkill[useID] = item;
	}
}

你可能感兴趣的:(c++)