求大神,帮忙分析下程序问题的原因
程序代码:
#include <iostream> #include <string> #include <vector> #include <cctype> #include <stdexcept> using namespace std; using std::string; using std::vector; struct Sales_data { Sales_data& combine(const Sales_data&); string isbn() const { return bookNo; } double avg_price() const; string bookNo; unsigned units_sold = 0; double revenue = 0.0; }; Sales_data add(const Sales_data&, const Sales_data&); ostream &print(ostream, const Sales_data&); istream &read(istream, Sales_data&); int main() { Sales_data total; if(read(cin, total)) { Sales_data trans; while(read(cin, trans) { if(total.isbn() == trans.isbn()) { (trans); } else { print(cout, total) << endl; cout << '\n'; total = trans; } } print(cout, total) << endl; } else { cerr << "No data?!" << endl; return -1; } return 0; } Sales_data& Sales_data::combine(const Sales_data &rhs) { units_sold += rhs.units_sold; revenue += rhs.revenue; return *this; } double Sales_data::avg_price() const { if(units_sold) return revenue/units_sold; else return 0; } Sales_data add(const Sales_data &lhs, const Sales_data &rhs) { Sales_data sum = lhs; (rhs); return sum; } ostream &print(ostream &os, const Sales_data &item) { os << item.isbn() << " " << item.units_sold << " " << item.revenue << " " << item.avg_price() << endl; return os; } istream &read(istream &is, Sales_data &item) { double price = 0; is >> item.bookNo >> item.units_sold >> price; item.revenue = item.units_sold * price; return is; }
这是问题程序的代码,无法通过编译。
编译器的错误提示是[Error] use of deleted function 'std::basic_istream<char>::basic_istream(const std::basic_istream<char>&)'
我觉得问题出在read函数上,于是我把read和print函数的定义放在main函数上面,竟然通过编译了。但是我不明白错误的原因,求大神指教。