本博文的创作思路源自《C++ Primer(4th Ed )》的习题15.20
运行环境Ubuntu 、g++
#include <iostream>
#include <string>
using namespace std;
class Item_base
{
public:
Item_base(const string &book = "Item_base", double SalesPrice = 1):
isbn(book), price(SalesPrice)
{
cout << "构造函数Item_base(const string&, double )" << endl;
}
virtual double NetPrice(size_t n) const //不同购买量不同计价方式
{
return n * price;
}
Item_base(const Item_base& it) //复制构造函数
{
//isbn = it.isbn;
//price = it.price;
cout << " 复制构造函数Item_base(const Item_base& it) " << endl; }
Item_base& operator =(const Item_base& right)
{
isbn = right.isbn;
price = right.price;
cout << "赋值函数Item_base::operator =(Item_base&