Код IT
← Каталог

Класс в C++ — this, static, friend и вложенные типы — Вложенные классы (nested)

Фрагмент из «Класс в C++ — this, static, friend и вложенные типы»: Вложенные классы (nested).

C++ main.cpp
class HashTable {
public:
    class Iterator {
        HashTable* table_;
        size_t index_;
        friend class HashTable;
        Iterator(HashTable* t, size_t i) : table_(t), index_(i) {}
    public:
        bool operator!=(const Iterator& other) const {
            return index_ != other.index_;
        }
    };
    Iterator begin();
    Iterator end();
};
class HashTable {
public:
    class Iterator {
        HashTable* table_;
        size_t index_;
        friend class HashTable;
        Iterator(HashTable* t, size_t i) : table_(t), index_(i) {}
    public:
        bool operator!=(const Iterator& other) const {
            return index_ != other.index_;
        }
    };
    Iterator begin();
    Iterator end();
};