Я создаю метод виртуального клонирования в своем классе, который я собираюсь продемонстрировать в своем основном файле. Но когда я пытаюсь это сделать, я получаю ошибки.C++ Метод виртуального клонирования, наследование исключений
Вот мой класс:
// includes
#include <string>
#include <exception>
#include <sstream>
namespace Vehicle_Renting {
using namespace std;
class Auto_Rent_Exception : public std::exception{
protected:
string error;
public:
Auto_Rent_Exception(){
}
virtual const string what() = 0;
virtual ~Auto_Rent_Exception() throw();
virtual Auto_Rent_Exception* clone() = 0;
};
class short_input : public Auto_Rent_Exception{
public:
short_input(const string errorMsg){
stringstream ss;
ss << errorMsg << ": short_input" << endl;
error = ss.str();
}
virtual const string what(){
return error;
}
virtual short_input* clone(){
return new short_input(*this);
}
};
}
А вот как я это с помощью:
cout << "Virtual Clone" << endl;
Auto_Rent_Exception* exc = new short_input("Smthing"); //Original copy
Auto_Rent_Exception* copy;
copy = exc->clone();
cout << exc->what();
cout << copy->what() << endl;
delete exc;
я получаю эти ошибки, которые я не знаю, как ремонт:
undefined reference to `vtable for Vehicle_Renting::Auto_Rent_Exception'
undefined reference to `Vehicle_Renting::Auto_Rent_Exception::~Auto_Rent_Exception()'
undefined reference to `vtable for Vehicle_Renting::Auto_Rent_Exception'
undefined reference to `Vehicle_Renting::Auto_Rent_Exception::~Auto_Rent_Exception()'
undefined reference to `Vehicle_Renting::Auto_Rent_Exception::~Auto_Rent_Exception()'
Пожалуйста, скопируйте и вставьте текст сообщения об ошибке, так что становится доступным для поиска. Тем не менее, я не уверен, что std :: exception можно копировать. Тем не менее, проблема в том, что в * вашем классе нет конструктора-копии, в котором используется 'short_input &'. Это тоже должно быть постоянным, иначе вы не сможете клонировать объекты, на которые вы постоянно ссылаетесь. –