Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

There is trouble passing CArray into the function. 1

Status
Not open for further replies.

sulacco

Technical User
Nov 8, 2002
74
RU
What's wrong with this code?

//declaration
Code:
GetArrFromName(CString name, CArray<CString,CString>arr);
...
Code:
//definition
void CMyClass::GetArrFromName(CString name, CArray<CString,CString>arr){
	


}
...
While I'm not using this function everything ok.
compiler don't bark at me
but when I started to use it, the compliler shows error message.

Code:
//using
CMyClass mymy;
CArray<CString,CStrin>arr;
CString name;
mymy.GetArrFromName(name,arr);
//error message
...
error C2664: 'GetArrFromName' : cannot convert parameter 2 from 'class CArray<class CString,class CString>' to 'class CArray<class CString,class CString>'
No copy constructor available for class 'CArray<class CString,class CString>'
MyListNew.cpp

 
The problem is that CArray is not meant to be copied, and since you are passing it by value to your function, a copy will be made.

To get it to work, change your function to use a const reference (and you might as well do that for the CString parameter too):
Code:
GetArrFromName([COLOR=blue]const[/color] CString[COLOR=blue]&[/color] name, [COLOR=blue]const[/color] CArray<CString,CString>[COLOR=blue]&[/color] arr);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top