Same for CMap, CList, and pretty much everything that uses templates (I guess).
I find it a bit hard to understand when to use which. It’s true that for classes and such, the <class, class&> form is usually what you want, but for basic types like int, float, etc., which form is preferred?
I would say that if you don’t really need something else, just use
CArray<Type>andARG_TYPEwould be its defaultconst TYPE&. Actually usingType&asARG_TYPEis not a good idea. This theoretically allowsCArrayto modify the object/value you passed to the corresponding method. Of courseCArraydoesn’t do anything like this but it is better to be on the safe side.If you look at the source code that is available within MS VC, you’ll see that
ARG_TYPEis used in a few methods as type for argument that holds new value for some element(s) of the array such asIf you making your choice between
Typeandconst Type&, then the only thing that is affected is how many times and which data would be copied. When value is passed by reference, only pointer to it is actually passed. This is really important for objects (additional call of copy constructor) but doesn’t really matter for simple types. Of course you can try to save a few bytes by forcing copyingcharorshortthat is smaller than corresponding pointer (32/64 bit depending on platform) but I don’t think that this really worth additional troubles. As I said before, I think that using defaultCArray<Type>is a good way unless you really have reasons to change it.