tags:

views:

8

answers:

0

Hello.

I'd like to extend std::exception and override its what() method so that every time that in my code I throw and exception of type myException()m the message "my exception" will be printed. (trying to keep it minimal)

I declare the class in a header and define my version of what() in a cpp class. The compiler complains: undefined reference to vtable. http://gcc.gnu.org/faq.html#vtables It seems the function in the cpp file is not recognized as a valid definition.

Thank you!


Exceptions.h


#ifndef EXCEPTIONS_H_
#define EXCEPTIONS_H_

#include <exception>
#include <string>
using namespace std;

class myException: public exception{
  public:
    virtual const char* what() const throw();
};

#endif

Exceptions.cpp


#include "Exceptions.h"

const char* myException::what() const throw(){
  return "my exception";
}