| 发表于:2008-01-22 23:14:08 楼主 |
在c++primer 4版的14.8题的解答感觉有点问题(重载操作符"> > "): istream& operator> > (istream& in,checkoutrecord &c) {in> > c.book_id> > c.title> > c.date_borrowed> > c.date_due > > c.borrower.first> > c.borrower.second; if(!in){ c=checkoutrecord(); return in; } c.wait_list.clear();//删除元素 while(in){ pair <string,string> *p=new pair <string,string> ; in> > p-> first> > p-> second; if(!in){ delete p; //原书题解里没有这行,我加的,需要吗? return in; } c.wait_list.push_back(p); } return in; } 这是类定义: class checkoutrecord{ public: friend istream& operator> > (istream&,checkoutrecord &); private: double book_id; string title; date date_borrowed; date date_due; pair <string,string> borrower; vector <pair <string,string> * > wait_list; }; 如果不写: delete p; 的话,是否回发生内存泄露? |
|
|
|
|