auto_ptr for arrays
Use
std::vector<BYTE> buffer(cbType);pType = (WM_MEDIA_TYPE*)&buffer[0];
or since C++11
std::vector<BYTE> buffer(cbType);pType = (WM_MEDIA_TYPE*)buffer.data();
instead.
Additional:If someone is asking if the Vectors are guaranteed to be contiguous the answer is Yes since C++ 03 standard. There is another thread that already discussed it.
If C++11 is supported by your compiler, unique_ptr can be used for arrays.
unique_ptr<BYTE[]> buffer(new BYTE[cbType]);pType = (WM_MEDIA_TYPE*)buffer.get();
There is nothing for this in the current std library. However, the future standard C++0x has an unique_ptr, which comes in replacement of auto_ptr, and which works with arrays.
A first implementation can be found here:unique_ptr