Can I inherit a template class and set it to a template subclass of the class I'm currently trying to inherit?

Awful name, I know. I will illustrate:

template <typename ValType> struct MemMapFileHashTable : MemMapFileStructured<MemMapFileHashTable<ValType>::kvp> {
    struct kvp {
        uint32_t key;
        ValType val;
    };

    MemMapFileHashTable(const char* fileName, bool write = false, int64_t chunkB = 65536) : MemMapFileStructured(fileName, write, chunkB) { }
};

So the idea is that I create a hash table with a specific ValType, which in turn has kvp with a specific ValType.

To use a class that inherits, I need to set kvp as a type specifier, however, since kvp is declared inside the hash table class, it will not let me. Is there any way to convince him otherwise?

I could just create an instance of MemMapFileStructured inside the hash table, I suppose, but this will be the fifth consecutive inheritance in the class lines that I built, and I don't want to break my cast.

+4
1

typedef. :

template<typename ValType> struct kvp_t {
    uint32_t key;
    ValType val;
};

template <typename ValType> struct MemMapFileHashTable : MemMapFileStructured<kvp_t<ValType>> {

    typedef kvp_t<ValType> kvp;

    MemMapFileHashTable(const char* fileName, bool write = false, int64_t chunkB = 65536) : MemMapFileStructured(fileName, write, chunkB) { }
};

, kvp , . . MemMapFileHashTable<ValType>::kvp - , . , - .

, ++, , , , , , , std::vector<TYPENAME>::iterator, . .

+1

Source: https://habr.com/ru/post/1628600/


All Articles