How to Write Collection Class Helper CompareElements?

  • Thread starter Thread starter chcw
  • Start date Start date
C

chcw

Guest
Hi,

I am using Visual C++ & MFC. Now I need to use CMap and the key is a special structure CMyKey defined by myself. Since the structure is large, I plan to use CMyKey& as the ARG_KEY. Therefore, I use CMap as below:

typedef CMap<CMyKey, CMyKey&, DWORD, DWORD> CMyMap;

Now I need to implement the collection class helper as described in https://msdn.microsoft.com/en-us/library/7y37x7cs.aspx

It said the function should be like this:

template<class TYPE, class ARG_TYPE>

BOOL AFXAPI CompareElements(

const TYPE* pElement1,

const ARG_TYPE* pElement2

);

So I write the specialization of the template function as below:

template< > BOOL AFXAPI CompareElements<CMyKey, CMyKey&> (const CMyKey* pElement1, const CMyKey&* pElement2)

{



}

But the compiler said a pointer to a reference(const CMyKey&*) is illegal. I have to modify the function as below:

template< > BOOL AFXAPI CompareElements<CMyKey, CMyKey> (const CMyKey* pElement1, const CMyKey* pElement2)

{



}

Now the compilation is fine. But I cannot understand why. Since I have already defined ARG_KEY as CMyKey&, not CMyKey, why I should use CMyKey instead of CMykey& as the ARG_TYPE?

Thanks

Continue reading...
 
Back
Top