Inherited Code Discussions | C++ | HackerRank

Inherited Code

  • + 1 comment

    following makes use of sstream. No need to create object on heap:

    const char* what() const throw() {
        stringstream ss;
        string error;
    
        ss << n; //Integer passed to exception object
    
        error = ss.str();
    
        return(ss.c_str());  
    }
    

    This makes use of "c_str()" which converts your std::string to const char* (which is what c syntax for representing strings)