Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Over riding error...Lax... C++ language spec violation maybe?

Tags:

c++

overriding

I have looked at this problem and don't see where the problem is. I'm not an expert at C++ so to me this looks OK. This used to compile without issue the last time I tried.

namespace yaaf {

/************************************************************************/
/*                                                                                          */
/*     Standard YAAF Errors                                                            */
/*                                                                                          */
/************************************************************************/

/*     XGYAAFError
 *
 *          YAAF Error; this is the root of my YAAF errors, and is
 *     a descendant of the standard exception class
 */

class XGYAAFError : public std::exception {
     public:
          explicit XGYAAFError(const char *);
          explicit XGYAAFError(const std::string &err);

          const char *what() const throw()
          {
              return fError.c_str();
          }

     private:
          std::string fError;
};

} // namespace yaaf

#endif

The GCC library base class...

  /**
   *  @brief Base class for all library exceptions.
   *
   *  This is the base class for all exceptions thrown by the standard
   *  library, and by certain language expressions.  You are free to derive
   *  your own %exception classes, or use a different hierarchy, or to
   *  throw non-class data (e.g., fundamental types).
   */
  class exception 
  {
  public:
    exception() throw() { }
    virtual ~exception() throw();

    /** Returns a C-style character string describing the general cause
     *  of the current error.  */
    virtual const char* what() const throw();
  };

The error " specification of overriding function is more lax than base version" is what I now get when I try to build.

I think that this may have to do with a change in the C++ language ( about 2004??) and where you can declare pointer within a derived class. But I'm not sure if that's the case here and how to go about fixing this.

Any ideas on what specifically is wrong or how I can fix this is appreciated.

Thanks

like image 738
user1580494 Avatar asked Aug 06 '12 23:08

user1580494


1 Answers

XGYAAFError has a member variable of type std::string, which has a nontrivial destructor that can throw any exception. std::exception, as you see, has a user-declared destructor that is declared as throwing no exceptions.

Therefore, because of the overriding rules, XGYAAFError needs a user-declared destructor with a throw() exception specification. I provided an in-depth explanation of this subject in the question, "How does an exception specification affect virtual destructor overriding?" See that question for details.

like image 153
James McNellis Avatar answered Sep 20 '22 15:09

James McNellis