samedi 25 juillet 2020

C++: how to return object's set state when used as logical value

I have some class that can be set or not:

Class obj;

I want its value, when used in logic, to return whether or not it's set:

if ( obj )
    obj.Clear();

if ( !obj )
    obj.Set( "foo" );

I thought of adding in an implicit conversion to bool, but I wonder if int would be necessary or whether there's a better way to go about this.

Aucun commentaire:

Enregistrer un commentaire