Inherited Code Discussions | C++ | HackerRank

Inherited Code

  • + 1 comment

    why did you define stringstream variable inside the constructor? and Why cant I define ss as a class variable, inside the private block ?

    class BadLengthException: public exception{
        stringstream ss;
        string error;
    public:
        BadLengthException(int n)
        {
            ss<<n;
            error = ss.str();
        }
        virtual const char* what() const throw()
        {
            return error.c_str();
        }
    };