c++ - How to inherit from std::runtime_error? -
for example:
#include <stdexcept> class { }; class err : public a, public std::runtime_error("") { }; int main() { err x; return 0; }
with ("")
after runtime_error
get:
error: expected '{' before '(' token error: expected unqualified-id before string constant error: expected ')' before string constant
else (without ("")
) get
in constructor 'err::err()': error: no matching function call 'std::runtime_error::runtime_error()'
what's going wrong?
(you can test here: http://www.compileonline.com/compile_cpp_online.php)
this correct syntax:
class err : public a, public std::runtime_error
and not:
class err : public a, public std::runtime_error("")
as doing above. if want pass empty string constructor of std::runtime_error
, way:
class err : public a, public std::runtime_error { public: err() : std::runtime_error("") { } // ^^^^^^^^^^^^^^^^^^^^^^^^ };
here live example show code compiling.
Comments
Post a Comment