【发布时间】:2016-05-18 12:18:06
【问题描述】:
我从抽象类继承有问题。
抽象类-头文件:
#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)
{
}
最后是错误:
GB 和 GBP 是枚举变量:
enum Country {GB, PL};
enum Currency {GBP, PLN};
【问题讨论】:
-
Client 类中有虚拟 dtor?
标签: c++ inheritance abstract-class