views:

75

answers:

3

Hi,

I am trying to return 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;
 }

////////////

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.

Thanks*strong text*

A: 

You cannot store a reference in an array type, and CArray is to be absolutely avoided at all costs as it uses memcpy to resize and not copy construction, breaking your code the instant you need something with a useful constructor.

DeadMG
+2  A: 

Erm, frist of all if RetArray is a member of ListMaker class and you call it from main(), you cannot call it like this: short nCode = RetArray(L"Name", myArray);

If RetArray is a static member, use short 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 RetArray declaration in ListMaker class. It might differ from the implementation in your cpp file, henve you get the C2511 error.

AOI Karasu
yes, I have modified as you have suggested, but I am still getting the same error. Just tell me how to return and call CArray properly.
osum
A: 

I think the problem is in CString&, try using CArray<CString, LPCTSTR> instead.

djeidot