If ARG_TYPE for CArray will be const or not

What is the difference between these two lines

CArray<MyClass, MyClass> MyArray CArray<MyClass, const MyClass & > MyArray 
0
c ++ templates mfc
source share
2 answers

MyClass is always copied to an array. But the first form copies it twice: the first time it is specified as a parameter of the Add or SetAt function, the second time internally. With the second form, you avoid the first copy.

+1
source share

In the first case, you need to have an Accessable instance constructor in MyClass , and MyClass will be passed by value (copied) in some CArray members (for example, in CArray::Add ).

+1
source share

All Articles