2016-05-18 3 views
0

У меня проблема с наследованием от абстрактного класса.Неопределенная ссылка на vtable (Наследование)

Абстрактный класс - файл заголовка:

#ifndef CLIENT_H 
    #define CLIENT_H 
    #include "country.h" 
    #include "currency.h" 
    #include "item.h" 
    #include "order.h" 
    #include <string> 
    #include <vector> 

    using namespace std; 

    class Order; 

    class Client { 
     string first_name; 
     string last_name; 
     int account_balance; 
     Country country; 
     Currency currency; 
     vector <Order> orders; 

    public: 
     Client (string first_name, string last_name, Country country, Currency currency); 
     void buy_item (Item item, unsigned quantity, unsigned order_ID); 
     void add_order (unsigned ID); 
     virtual void pay (unsigned order_ID) = 0; // 
    }; 

    #endif // CLIENT_H 

Абстрактный класс - .cpp файл:

#include "client.h" 

    Client::Client (string first_name, string last_name, Country country, Currency currency) 
     : first_name(first_name), last_name(last_name), country(country), currency(currency) 
    { 
    account_balance = 0; 
    } 

Наследование класса - Заголовочный файл:

#ifndef ENGLISHCLIENT_H 
    #define ENGLISHCLIENT_H 
    #include "client.h" 
    #include <string> 

    using namespace std; 

    class EnglishClient : public Client { 
    public: 
     EnglishClient (string first_name, string last_name); 
     void pay (unsigned order_ID); 
    }; 

    #endif // ENGLISHCLIENT_H 

Наследование класса -. cpp-файл:

#include "englishclient.h" 

    EnglishClient::EnglishClient (string first_name, string last_name) 
     : Client(first_name, last_name, GB, GBP) 
    { 
    } 

И, наконец, ошибка:

enter image description here

GB и GBP являются перечисляемые переменные:

enum Country {GB, PL}; 

enum Currency {GBP, PLN}; 
+0

есть виртуальный dtor в классе Client? –

ответ

0

Вы забыли реализацию методов Client::buy_item, Client::add_order и EnglishClient::pay

+0

Я думал, что могу скомпилировать этот код, прежде чем применять эти методы. В любом случае, сейчас он работает, спасибо большое :) –

0

Вы никогда не определяли EnglishClient::pay, Client::buy_item или Client::add_order. Для клиента либо определить их, либо задать их как абстрактные: void buy_item (Item item, unsigned quantity, unsigned order_ID)=0; (то же для add_order) `и определить их в подклассе.

+0

Спасибо, сейчас работает :) –

Смежные вопросы