0
votes

Is it possible to use const parameter to CArray

I am currently using CArray like this but it won't compile:

typedef CArray<const CString, const CString&> data_container;

And I always get this compile error :

error C2664: 'ATL::Checked::memcpy_s' : cannot convert parameter 1 from 'const CString *' to 'void *'

2

2 Answers

2
votes

The code that CArray uses expects your TYPE to be non-const, so it can cast to void* (as noted by the compilation error message).

You could store const CString pointers, which would give you a const CString when dereferenced. You do have the burden of allocating/cleaning up that memory now. An alternative is to wrap a CString in a simple class, that has a "GetString" function that returns a const reference to its internal CString instance.

0
votes

Apparently no. Why would you want to do that?