Inherited Code Discussions | C++ | HackerRank

Inherited Code

  • + 0 comments

    I cannot see the proper solution where we inherit all methods. So, here it is:

    class BadLengthException : public exception {
    private:
        string message;
    public:
        BadLengthException(const int& msg) : message(to_string(msg)) {}
        const char* what() const noexcept override{
            return message.c_str();
        }
    };
    

    To be syntactically coherent with error messages, we need to return the error as a C-style string, not an integer.