I was wondering why the bool conversion operator of a shared_ptr works fine in an if-statement
, but not in the implicit conversion to the (bool) return value..
std::shared_ptr<const OfflineContainer> m_pContainer;
bool MyClass::IsInitialized() const
{
if (m_pContainer) // compi;es
return true;
return m_pContainer; // won't compile
}
The compiler message:
Error C2440 'return': cannot convert from 'const std::shared_ptr<const MyClass>' to 'bool'