1

shared_ptr が shared_ptr.reset() を呼び出さなかったかどうかを確認しようとしています

私は

std::shared_ptr<Shape> m_shape; 

そして私はやろうとしています

 if(m_shape.reset()==false)
 {
    dothis();
 }

m_shape がアクティブで使用されているかどうかを確認したい...そして、shared_ptr が使用されなくなったときにリセットが表示される

しかし、式には算術演算、列挙型、ポインターが必要であるというm_shapeのエラーが発生し続けます

4

1 に答える 1

1

reset() is a function that resets the shared_ptr, and returns void. It most certainly does not tell you if the shared_ptr is currently managing an object. In fact, calling it guarantees that it's no longer managing an object.

Instead, shared_ptr has a conversion to bool that tells you if it's currently managing an object. So you can just say

if (m_shape) {
    // m_shape has an object
}
于 2013-03-28T06:14:44.027 に答える