5

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

coelhudo
  • 4,710
  • 7
  • 38
  • 57
user1580494
  • 51
  • 1
  • 3

1 Answers1

5

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.

Community
  • 1
  • 1
James McNellis
  • 348,265
  • 75
  • 913
  • 977
  • James....Thanks for the prompt response. I followed the links and read them. I also read about this in my books on C++. Tried to implement a fix but it failed. Clearly I am not getting what needs to be done. I hate to impose,, but could you specifically indicate what you would change and how.. I will try that if its different from what I did. Again thanks for the assist from a C++ newbie. – user1580494 Aug 07 '12 at 20:02
  • 1
    You need to provide a destructor for `XGYAAFError`. For example, `~XGYAAFError() throw() { }`. – James McNellis Aug 07 '12 at 21:03
  • Thanks that clears it up.. I just didn't get it the first time I read this stuff thru. – user1580494 Aug 07 '12 at 22:32