I have problem with inheriting from abstract class.
Abstract class - header file:
#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
Abstract class - .cpp file:
#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;
}
Inheriting class - header file:
#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
Inheriting class - .cpp file:
#include "englishclient.h"
EnglishClient::EnglishClient (string first_name, string last_name)
: Client(first_name, last_name, GB, GBP)
{
}
And finally the error:
GB and GBP are enum variables:
enum Country {GB, PL};
enum Currency {GBP, PLN};
您忘记了方法Client::buy_item
, Client::add_order
和EnglishClient::pay
You never defined EnglishClient::pay
, Client::buy_item
or Client::add_order
. For client, either define them or set them as abstract: void buy_item (Item item, unsigned quantity, unsigned order_ID)=0;
(same for add_order)` and define them in subclass.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.