Inherited Code Discussions | C++ | HackerRank

Inherited Code

  • + 4 comments

    Please pay attention that solutions from previous comments produce expected result but are bad.

    class BadLengthException: public exception {
        int N;
        public:
        BadLengthException(int N){this->N = N;}
        int what(){return N;}
    };
    

    According to standard class std::exception has the next method what()

    virtual const char* what() const noexcept; // C++11
    

    And compile produces reasonable error for this:

    int what() const noexcept; // C++11
    
    solution.cc:13:9: error: conflicting return type specified for ‘virtual int BadLengthException::what() const’
         int what() const*
    

    So I suppose that author expected int->string conversion (see sstream header) but it is another question.