I am trying to return a CArray from a function and trying to call the function from another class
short ListMaker::RetArray(CString szName, CArray<CString, CString&> &szarr_Names) {
szarr_Names.Add(szName);
return 0;
}
int main() {
//..
CArray<CString, CString&> myArray;
ListMaker LM;
short nCode = LM.RetArray(L"Name", myArray);
//..
}
I am getting following errors:
Error 1 error C2664: 'RetArray' : cannot convert parameter 2 from 'CArray<TYPE,ARG_TYPE>' to 'CArray<TYPE,ARG_TYPE>'
Error 2 error C2511: 'short RetArray(CString,CArray<TYPE,ARG_TYPE> &)' : overloaded member function not found in 'ListMaker'
Please tell me the correct way to define and access the return value of the CArray.
Erm, frist of all if
RetArrayis a member ofListMakerclass and you call it frommain(), you cannot call it like this:short nCode = RetArray(L"Name", myArray);If
RetArrayis a static member, useshort nCode = ListMaker::RetArray(L"Name", myArray);. It it’s non-static, use instance,short nCode = listMakerInstance.RetArray(L"Name", myArray);.Check your header file for
RetArraydeclaration inListMakerclass. It might differ from the implementation in your cpp file, hence you get the C2511 error.