From: marcomb on 28 Aug 2007 07:58 thanks for all answers, i've more clear the concept...i still haven't understood the real difference between CArray<CPoint*,CPoint*> myPtrArray; and CTypedPtrArray<CObList,CPoint*>myPtrArray; CTypedPtrArray stores pointers instead of object...but with CArray<CPoint*,CPoint*> myPtrArray; maybe i don't be storing pointers instead of objects themselves?
From: David Wilkinson on 28 Aug 2007 09:19 marcomb wrote: > thanks for all answers, i've more clear the concept...i still haven't > understood the real difference between > CArray<CPoint*,CPoint*> myPtrArray; > and > CTypedPtrArray<CObList,CPoint*>myPtrArray; > > CTypedPtrArray stores pointers instead of object...but with > CArray<CPoint*,CPoint*> myPtrArray; > maybe i don't be storing pointers instead of objects themselves? marcomb: First of all, you must decide whether you want to store objects or pointers. For a simple class like CPoint you are usually best to store objects, but for a class that is expensive to copy you may be better using pointers. Also, pointers must be used if you have a heterogeneous collection (store base class pointers). If you want to store objects, you should use CArray<CPoint, CPoint&> If you want to use pointers, you could use CArray<CPoint*, CPoint*> You could also use CTypedPtrArray<CPtrArray, CPoint*> Note that CTypedPtrArray must be used with CObArray or CPtrArray as the first template argument (not CObList as you suggest). Since CPoint is not derived from CObject, you should use CPtrArray (which is an array of void pointers). Personally, I do not see the purpose of CTypedPtrArray, when you could use CArray instead. But I myself would always use std::vector anyway. The C++ standard library can be imposing at first, but IMHO the collection classes are much simpler to work with than the multitude of MFC ones with their confusing double template argument. For most things, std::vector and std::map are all I use. Occasionally std::set or std::list. Very occasionally std::multimap and (to date) never std::multiset. -- David Wilkinson Visual C++ MVP
From: David Webber on 28 Aug 2007 09:59
"David Wilkinson" <no-reply(a)effisols.com> wrote in message news:eUye%23XX6HHA.5984(a)TK2MSFTNGP04.phx.gbl... > Personally, I do not see the purpose of CTypedPtrArray, when you could use > CArray instead. I *think* CPtrArray around which CTypedPtrArray is a wrapper, existed in MFC before CArray. I may be wrong. In any case, IIRC, CArray performs some very non-standard shenanigins vis-a-vis memory allocation and copy constructors: I remember its source code being quite a revelation a few years back. CPtrArray will surely avoid all that completely and (with or without CTypedPtrArray) may therefore be preferable. > But I myself would always use std::vector anyway. These days so do I. Dave -- David Webber Author of 'Mozart the Music Processor' http://www.mozart.co.uk For discussion/support see http://www.mozart.co.uk/mzusers/mailinglist.htm |