The MFC CArray class has two template parameters (from MSDN):
template < class TYPE, class ARG_TYPE = const TYPE& >
class CArray
...
The default parameter for ARG_TYPE is const TYPE&, and some questions on SO ask when to use a type different from the default (e.g. Should the ARG_TYPE for a CArray be const & or not, or What's the difference between CArray and CArray ?).
My questions are now: Are there reasonable use cases of CArray where the ARG_TYPE isn't TYPE or const TYPE&, e.g. another class? What are the reasons for these usages?
My guess is that, it should be related to inheritance hierarchy.
struct B {};
struct D : B {};
CArray<D, const B&> myArray;
You may want to have the base class as the receiving argument, which can receive a const reference from the derived class.
My best example is CArray <CString, LPCTSTR>. In fact, I recall CArray <CString, CString&> didn't work very well...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With