本文介绍了custon类的地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我创建了一个如下所示的类

Hi all,
I created a class as below

class CPatUser : public CObject
{
public:
	CString Login;
	int NbrTentMax;
	int CurrNbrTent;

	CPatUser(CPatUser &X)
	{
		this->Login = X.Login
		this->CurrNbrTent = X.CurrNbrTent;
		this->NbrTentMax = X.NbrTentMax;
	};

	void CPatUser::operator =(CPatUser &X)
	{
		this->Login = X.Login;
		this->NbrTentMax = X.NbrTentMax;
		this->CurrNbrTent = 0;
	};
};
typedef CTypedPtrArray<CPtrArray, CPatUser*> CPatUserCAList;



在我的应用程序的某些部分,我尝试在地图中插入该类的新实例:



and in some part of my application i try to insert into a map a new instance of the class :

CPatUser* ThePartUser;
	if(LoginUsers.find(TheUser->UserName) ==  LoginUsers.end())
	{
		ThePartUser ->Login = Name;
		ThePartUser->NbrTentMax = TheUser->NbrTentMax;
		ThePartUser->CurrNbrTent = 0;
		<big>LoginUsers.insert(std::pair<CString, CPatUser>(Name, ThePartUser));</big>
	}



但是在编译时出现此错误:



but when compiling i get this error :

<br />
error C2665: ''std::pair<_Ty1,_Ty2>::pair'' : none of the 3 overloads could convert all the argument types



我认为这与自定义类的某些问题有关,例如复制构造函数或某事.

有什么主意吗?

谢谢.



i think is related to some issue with a custom class such as copy constructor or sth lile that.

Any idea ?

Thank you.

推荐答案

std::make_pair< CString, CPatUser *>(Name, ThePartUser);




[更新]
抱歉,格式代码中有顽皮的拼写错误. CP(作为CodeProject)或CP(作为Carlo Pallini)都喝醉了.现在应该修正它们(错别字).
[/update]




[update]
Sorry there were naughty typos in formatting code. Either CP (as CodeProject) or CP (as Carlo Pallini) was drunk. They (the typos) should be fixed, now.
[/update]


这篇关于custon类的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 11:48