#pragma once
#include"Book.h"
#include<vector>
class BookShelf {
private:
std::vector<Book> books;
public:
class Iterator;
friend class Iterator;
class Iterator {
BookShelf& bookshelf;
int index;
public:
Iterator(BookShelf& bs,int id=0) :bookshelf(bs),index(id){};
bool hasNext() {
if (index<bookshelf.books.size()) {
return true;
}
return false;
}
Book next() {
return bookshelf.books[index++];
}
};
void pushBook(Book book) {
books.push_back(book);
}
};
迭代器模式C++实现
最新推荐文章于 2025-02-19 00:15:00 发布
1538

被折叠的 条评论
为什么被折叠?



