3

MFC has two similar templated container classes: CTypedPtrArray and CArray.

CTypedPtrArray is supposed to be an array of typed-pointers, while CArray can be an array of any type (including pointers), and I see nothing in the documentation that suggest that CTypedPtrArray is any safer/faster/easier than a CArray.

Is there any meaningful difference between these two?

CTypedPtrArray<CPtrArray, CMyFoo*>  arrayOne;
CArray<CMyFoo*, CMyFoo*>            arrayTwo;
Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
abelenky
  • 63,815
  • 23
  • 109
  • 159
  • 2
    There's more than one, but the first and most important one might be that CTypedPtrArray let you specify its base class through the first template parameter where CArray always derives from CObject. The docs do also list hints about the advantages: "In addition, the CTypedPtrArray wrapper performs much of the casting that would be required if you used CObArray or CPtrArray." – wonko realtime May 11 '15 at 12:28
  • Did you find out the answer? – Aykhan Hagverdili Nov 22 '20 at 06:32

1 Answers1

1

CArray uses memcpy_s to move elements so not compatible objects that require the constructor to be called. Always use CTypedPtrArray for storing objects derived from CObject.

Jon Eldridge
  • 169
  • 2
  • 7