Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include "product.h"
- using namespace std;
- struct Product {
- public:
- string type;
- Product() = default;
- Product(string type) {
- this->type = type;
- }
- string GetType() const {
- return this->type;
- }
- friend bool operator==(const Product& a, const Product& b) {
- return a.GetType() == b.GetType();
- }
- };
- int main() {
- const Product searchProduct("laptop");
- Product product1("phone");
- Product product2("laptop");
- Product product3("phone");
- Product product4("phone");
- vector<Product> storage;
- storage.push_back(product1);
- storage.push_back(product2);
- storage.push_back(product3);
- storage.push_back(product4);
- cout << count(storage.begin(), storage.end(), searchProduct);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement