How do I override the bool operator in a C++ class?

后端 未结 4 1307
遇见更好的自我
遇见更好的自我 2020-12-09 10:31

I\'m defining a ReturnValue class in C++ that needs to report whether a method was successful. I want objects of the class to evaluate to true on s

4条回答
  •  情话喂你
    2020-12-09 11:25

    Well, you could overload operator bool():

    class ReturnValue
    {
        operator bool() const
        {
            return true; // Or false!
        }
    };
    

提交回复
热议问题