c++ - Why is this compiler error happening? -
i working on exception handling piece of software write in c++. encounter compiler error (using g++ (gcc) 4.8.1 / mingw32) don't understand, here minimal example:
#include <iostream> #include <exception> class bad_img_load: public std::exception { //public: virtual const char* what() const throw(){ return "an image not loaded."; } }; int main () { try{ throw bad_img_load(); }catch (bad_img_load& e){ std::cout << e.what() << '\n'; } return 0; }
the error is:
a.cpp: in function 'int main()': a.cpp:6:22: error: 'virtual const char* bad_img_load::what() const' private virtual const char* what() const throw(){ ^ a.cpp:15:25: error: within context std::cout << e.what() << '\n'; ^
note if uncomment line 'public:' works fine. class 'exception' inherits defines public. don't understand why error crops @ all.
it doesn't matter if whether class you're inheriting has it's members public. if overload inherited class' public function (in code implicitly specified) private access-specifier, overload private. technically, you're overloading access-specifier too.
Comments
Post a Comment