CComBSTR::operator &


Returns the address of the BSTR stored in the m_str member.


BSTR* operator &( ) throw( );


CComBstr operator & has a special assertion associated with it to help identify memory leaks. The program will assert when the m_str member is initialized. This assertion was created to identify situations where a programmer uses the & operator to assign a new value to m_str member without freeing the first allocation of m_str. If m_str equals NULL, the program assumes that m_str wasn't allocated yet. In this case, the program will not assert.

This assertion is not enabled by default. Define ATL_CCOMBSTR_ADDRESS_OF_ASSERT to enable this assertion.



void MyInitFunction(BSTR* pbstr)
   ::SysReAllocString(pbstr, OLESTR("Hello World"));
CComBSTR bstrStr ;
// bstrStr is not initialized so this call will not assert.

CComBSTR bstrStr2(OLESTR("Hello World"));
// bstrStr2 is initialized so this call will assert.
::SysReAllocString(&bstrStr2, OLESTR("Bye"));


Header: atlbase.h

See Also

CComBSTR Class