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();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)