Some behaviour with ScopedPointer I don't understand

Hi all

I'm on VS2010, and have the following code:

const bool bStereo = (m_uNbChannels == 2);
const bool b51Srnd = (m_uNbChannels == 6);
ScopedPointer<float*> ptrProcBuffer = new float*[m_uNbChannels];

m_AnalyzeFilter.ProcessBlock(bStereo? ptrProcBuffer : nullptr, b51Srnd? ptrProcBuffer : nullptr, kBlockLength);



bool ProcessBlock(float** const ppfStereoData, float** const ppf51SrndData, const unsigned int uBlockSize);

Well, when calling the processBlock function I would expect the scopedpointer to call its float** cast operator then the .get() method to be called, nothing else. 

But instead, a new ScopedPointer object is constructed from the existing one, and then the original one is reset...


my only workaround so far is to call the .get() method explicitly like:

m_AnalyzeFilter.ProcessBlock(bStereo? ptrProcBuffer.get() : nullptr, b51Srnd? ptrProcBuffer.get() : nullptr, kBlockLength);

Thanks for advise



In any case your code is wrong as 
ScopedPointer will not call delete [] leading to either leak or crash


use std::vector and &myVector[0] IMHO

oh yes true, I always do this error, should use my own scoped pointer class



No... you shouldn't use any kind of scoped pointer for holding arrays.

Use std::vector, or Array. Or since I presume you're trying to hold a set of audio channels, use a AudioSampleBuffer, which is designed for exactly that purpose.

ok my previous mistake apart, still.. 

using a custom ScopedPointer class (where you can specify the deleter to be free, delete, delete[] or CoTaskMemFree) I still get exactly the same behaviour.. and I'm still curious about it..

isn't it because the ScopedPointer constructor is not declared "explicit" ?

mm maybe, have to give it a try