class BookList{
public:
friend Book;
BookList(){ }
void insertBook(Book* b){ bookList.push_back(b);}//插入图书
void addItem(Book* newb,int n){//add n new books添加新书
newb->chRemain(n);
bookList.push_back (newb);
}
void chRemain(Book* b,int n){//查询剩余数量
i=find(bookList.begin (),bookList.end (),b);
Book * b1 =*i;
b1->chRemain(n);
}
void showAll(){//显示所有图书信息
int num=0;
for(i=bookList.begin ();i!=bookList.end ();i++){
Book * b =*i;
b->getDetail();
num++;
}
//cout<<"共有 "<<num<<" 种书。"<<endl;
}
void outBook(Book*b){//出库
i=find(bookList.begin (),bookList.end (),b);
Book * b1 =*i;
b1->decrease ();
}
void inBook(Book*b){//入库
i=find(bookList.begin (),bookList.end (),b);
Book * b1 =*i;
b1->increase ();
}
int calculate(){//calculate the num of the kinds
int num=0;
for(i=bookList.begin ();i!=bookList.end();i++)
num++;
return num;
}
void checkBook(Book*b){//check one book's detail
strcpy(bookName,b->getName());
strcpy(bookAuthor,b->getAuthor());
i=find_if(bookList.begin(),bookList.end (),sameBook);//b,
Book * b1 =*i;
b1->getDetail ();
}
/*find_if:条件查找
find_if( InputIter first,InputIter last, pred)
pred是条件谓词,可以是函数,也可以是类。
类要重载运算符()带一个类型参数。
当满足pred(*inputiter)==true时,返回迭代器位置,
否则返回last。*/
/*struct sameBook
{
bool operator()(Book*now)
{
if(strcmp(now->getName(),bookName)==0 && strcmp(now->getAuthor(),bookAuthor)==0)
return true;
else
return false;
}
};*/
bool sameBook(Book*now){//Book*b,
if(strcmp(now->getName(),bookName)==0 && strcmp(now->getAuthor(),bookAuthor)==0)
return true;
else
return false;
}
private:
list<Book*>bookList;
list<Book*>::const_iterator i;
list<Book*>::iterator time;
int allkind;
char*bookName;
char*bookAuthor;
};
错误提示里说的很明白啦,类型不对嘛