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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -