C++ primer 第五版 第十六章练习答案

16.62

#include <iostream>
#include <unordered_set>
#include"Sales_data.h"
using namespace std;
namespace std {
    template<>
    struct hash<Sales_data> {
        typedef size_t result_type;
        typedef Sales_data argument_type;
        size_t operator()(const Sales_data& s)const;
    };
    size_t hash<Sales_data>::operator()(const Sales_data& s)const {
        return hash<string>()(s.bookNo) ^
            hash<unsigned>()(s.units_sold) ^
            hash<double>()(s.revenue);
    }

}
int main() {
    unordered_set<Sales_data>SDset;
    Sales_data obj1("C++Primer", 50, 128);
    SDset.insert(obj1);
}

猜你喜欢

转载自blog.csdn.net/Leslie5205912/article/details/80458589
今日推荐