本文主要是介绍C++ 模板多继承,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#include <iostream>
#include<string>
#include <unordered_set>
class Customer{
private:
std::string name;
public:
Customer(std::string const&n):name(n){}
std::string getName() const{
return name;
}
};
struct CustomerEq{
bool operator()(Customer const&c1,Customer const&c2)const{
return c1.getName() == c2.getName();
}
};
struct CustomerHash {
std::size_t operator()(Customer const &c) const {
return std::hash<std::string>()(c.getName());
}
};
template<typename ...Bases>
struct Overloader:Bases...
{
using Bases::operator()...;
};
int main() {
using CustomerOP = Overloader<CustomerHash,CustomerEq>;
std::unordered_set<Customer,CustomerHash,CustomerEq>col1;
std::unordered_set<Customer,CustomerOP,CustomerOP>col2;
std::cout << "Hello, World!" << std::endl;
return 0;
}
这篇关于C++ 模板多继承的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!