我这里有这个类(这是一个 .h 文件)
#ifndef STORE_H_
#define STORE_H_
#include <iostream>
#include <set>
#include "list.h"
#include "Album.h"
#include "Customer.h"
class Store {
public:
static const int currentYear = 2013;
Store();
void addAlbum(int barcode, int price, int year, int numPurchased, string title, string artist);
void removeAlbum(int barcode);
void addCustomer(int id, string name);
void createNewOrder(int id, int ordNum);
void addToOrder(int ordNum, int barcode);
void removeFromOrder(int ordNum, int barcode);
void payOrder(int ordNum);
string getRecommendations(int numOfRecommendations) const;
string getInventoryReport() const;
string getCustomersReport() const;
string getCustomerReport(int id) const;
string getRevenueReport() const;
~Store();
bool albumsCompare(Album album1, Album album2);
bool customerCompare(Customer customer1, Customer customer2);
std::set<Album> albums;
std::set<Customer> customers;
};
#endif /* STORE_H_ */
我正在尝试访问设置的“专辑”
std::set<Album> albums;
从这里(.cpp 文件)
void addAlbum(int barcode, int price, int year, int numPurchased, string title, string artist) {
if(barcode <= 0){
throw INVALID_BARCODE();
}
if(price <= 0){
throw INVALID_PRICE{};
}
if(year > Store::currentYear){
throw INVALID_YEAR();
}
if(numPurchased < 0){
throw INVALID_NUM_PURCHASED();
}
if(Album::findBarcode(Store::albums, barcode) != Store::albums.end()){
throw BARCODE_ALREADY_EXISTS();
}
}
但我收到错误:无法调用成员函数'std::set::iterator Album::findBarcode(const std::set&, const int&)'
任何解决此问题的帮助将不胜感激!
这是 findBarcode 函数
#include "Album.h"
std::set<Album>::iterator Album::findBarcode (std::set<Album>& set,int& barcode){
Album data = Album();
for (std::set<Album>::iterator i = set.begin(); i != set.end(); i++){
Album data = *i;
if(data.barcode == barcode){
return i;
}
}
return set.end();
}