I’ve been trying to find what the problem is to this following code part. I’ve written a custom exception class where I have a base class for stack errors, and then some classes deriving from it one of them called stack_full_error.
I have some problem compiling it though, I get the following error.
Undefined first referenced
symbol in file
stack_error::~stack_error() /var/tmp//ccFwZ5Kd.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
It says something about the destructor, and I have been trying some things to fix it, with no success. Anyway I hope someone can tell me what the problem is.
class stack_error : public exception
{
public:
stack_error(string const& m) throw()
: exception(), msg(m) {};
virtual ~stack_error() throw() =0;
virtual const char* what() const throw()
{
return msg.c_str();
}
private:
string msg;
};
class stack_full_error : public stack_error
{
public:
stack_full_error() throw()
: stack_error("Exception: stack full") {};
~stack_full_error() throw() {};
};
And here where I call the exception for this first time
template <class T>
void Stack<T>::push(T i)
{
if(is_full())
throw stack_full_error();
this->first = new Node<T>(this->first, i);
amount++;
}
Pure virtual or not,
stack_errormust define its destructor because it is implicitly called fromstack_full_errordestructor. You should add :in an implementation file.