7.5.1

7.36

struct X {
  X (int i, int j): base(i), rem(base % j) { }
  int rem,base;
};

因为rem在base之前声明,所以现初始化,但是rem的初始化需要base,所以错误
修改:

struct X {
  X (int i, int j): base(i), rem(base % j) { }
  int base, rem;
};

7.37

Sales_data first_item(cin);   // Sales_data(std::istream &is) ;

int main() {
  Sales_data next;         
  // Sales_data(std::string s = "");               
  //bookNo = "", cnt = 0, revenue = 0.0
  Sales_data last("9-999-99999-9");          //Sales_data(std::string s = ""); 
  //bookNo = "9-999-99999-9", cnt = 0, revenue = 0.0
}

7.38

Sales_data(std::istream &is = std::cin) { read(is, *this); }

7.39
不合法,因为当使用一个构造函数不给参数的时候,2个构造函数都复合条件,具有2义性 所以不合法

7.40

#include <iostream>
#include <string>

class Book 
{
public:
    Book(unsigned isbn, std::string const& name, std::string const& author, std::string const& pubdate)
        :isbn(isbn), name(name), author(author), pubdate(pubdate)
    { }

  Book(std::istream &in) 
    { 
        in >> isbn >> name >> author >> pubdate;
    }

private:
    unsigned isbn;
    std::string name;
    std::string author;
    std::string pubdate;
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值