struct empty_stack: std::exception // don't know what the code after : means
This means that empty_stack
publicly inherits from std::exception
which is the base class for standard exceptions.
Note: If the inheritance type is not specified, the default type of inheritance depends on the inheriting type. It's private
if inheriting type is class
and public
if inheriting type is struct
.
const char* what() const throw(); //don't understand this line either
This means that what()
is a function that does not modify the non-mutable members of the class it is part of and does not throw any exception. But it is a bit misleading to have throw()
at the end to mean that it does not throw.
So, from C++11 onwards, we have the noexcept
specifier. Using this in a function declaration like the one below means that the function is declared not to throw any exceptions.
const char* what() const noexcept;
Note: throw()
is deprecated and will be removed in C++20.