模板
友元模板类
- 就是说在一个类中声明一个友元类,然后这个友元类也是一个模板类
template<typename K, typename V, typename KofT, typename hash>
class Hash{
private:
template<typename InK, typename Ref, typename Ptr, typename InKofT, typename Inhash>
friend struct Iterator;
这里最重要的是
- friend后的struct不能少
- Iterator的模板不能少,而且模板不能重名(这好像也和编译器有关,我使用的g++是不允许重名)
模板参数的传递
template<typename K>
struct KofT{
K operator()(const K& value) { return value; }
};
template<typename K, typename hash = HashFunc<K>>
class unoredred_set{
public:
using iterator = typename Hash<K,K,KofT<K>,hash>::HashIterator;
这里在传递KofT时不要忘了带上模板参数