Article ID: 138695
Article Last Modified on 9/18/2003
template<class TYPE>
inline void AFXAPI ConstructElements(TYPE* pElements, int nCount)
{
ASSERT(nCount == 0 ||
AfxIsValidAddress(pElements, nCount * sizeof(TYPE)));
// First do bit-wise zero initialization.
memset((void*)pElements, 0, nCount * sizeof(TYPE));
// Then call the constructor(s).
for (; nCount--; pElements++)
::new((void*)pElements) TYPE;
}
template<class TYPE>
inline void AFXAPI DestructElements(TYPE* pElements, int nCount)
{
ASSERT(nCount == 0 ||
AfxIsValidAddress(pElements, nCount * sizeof(TYPE)));
// Call the destructor(s).
for (; nCount--; pElements++)
pElements->~TYPE();
}
NOTE: In C++, when resolving a reference to a templated function, it
examines all nontemplate instances of the function (the specialized functions)
first. Then it examines all template instances of the function. Therefore, if
you specialize the above functions in your applications when you use Visual C++
2.0, your program still should be compatible with Visual C++ 4.x without any
changes. Additional query words: template MFC4.0 dskbsweep
Keywords: kbbug kbnoupdate kbdocerr KB138695