Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I created a class as below
C++
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 :

C++
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.
Posted

1 solution

No surprise: your trying to make a std::pair< CString, CPatUser > with the couple (Name, ThePartUser) where the latter is a pointer to a CPatUser object. If you need to store pointers then you must use
C++
std::make_pair< CString, CPatUser *>(Name, ThePartUser);



[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]
 
Share this answer
 
v5
Comments
Schehaider_Aymen 24-Jan-12 5:51am    
I did what you sai and i had this error :


error C2558: class 'CPatUser' : no copy constructor available or copy constructor is declared 'explicit'


i even add the word explicit word :


explicit CPatUser(CPatUser &X)
{
this->Login = X.Login;
this->CurrNbrTent = X.CurrNbrTent;
this->NbrTentMax = X.NbrTentMax;
};
Schehaider_Aymen 24-Jan-12 6:00am    
Sorry I did not see the make_pair instead of pair :

i make it as below :


...
LoginUsers.insert(std::make_pair(<cstring,>(Name, ThePartUser *)));


and here the error (s)


error C2143: syntax error : missing ')' before '<'
error C2780: 'std::pair<_Ty1,_Ty2> std::make_pair(_Ty1,_Ty2)' : expects 2 arguments - 0 provided

Schehaider_Aymen 24-Jan-12 6:26am    
Thank you Carlo Pallini, that works now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900