C++ symbol referencing error

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++;
}

Answers


Pure virtual or not, stack_error must define its destructor because it is implicitly called from stack_full_error destructor. You should add :

stack_error::~stack_error() {}

in an implementation file.


Need Your Help

event_base* vs unique_ptr<event_base>

c++ c++11 unique-ptr libevent

The code I'm developing tries to avoid handling bare pointers, but I want to add some event based functinalities to it - I would use smart pointers here too, but as I understand it, this would mean...

Get implemented types of generic interface

c# linq generics reflection interface

I have an generic interface and I would like to have a list of the implemented data types.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.