2

I am trying to get this to compile, but having trouble with the nested class.

struct TKey {
    char a[2];
};

template<class TKEY, class TOBJ>
struct CHash {
    struct TNode {
        TKEY Key;
        TOBJ Obj;
    };
    int stuff;
};

template <class TKEY, class... ARGS>
class CNested : public CHash<TKEY, int> {
public:
    typedef CNested<ARGS...>            TNested;

    template<class TKEY1, class... ARGS1>
    struct TNodeType {
        typedef typename TNested::TNodeType<ARGS1...>::Type Type;
    };

    template<class TKEY>
    struct TNodeType<TKEY> {
        typedef TNode Type;
    };

    CNested() { }

};

// recursive template, tail
template <class TKEY, class TOBJ>
class CNested<TKEY, TOBJ> : public CHash<TKEY, TOBJ> {
public:
    CNested() { }
};


int main(int argc, char* argv[])
{
    // p should have type of CNested<TKey, TKey, int>::TNode*
    CNested<TKey, TKey, TKey, int>::TNodeType<TKey>* p; 
    return 0;
}
1

1 Answer 1

3

TNodeType is a dependent template name, thus you need:

typedef typename TNested::template TNodeType<ARGS1...>::Type Type;
                          ^^^^^^^^

Also in nested struct TNodeType argument TKEY shadows argument TKEY of outer class CNested, so you would need to change to:

template<class TKEY1>
struct TNodeType<TKEY1> {
    typedef TNode Type;
};
Sign up to request clarification or add additional context in comments.

1 Comment

Oh yeah....that TKEY is a typo....from when I had to pare down my code to ask the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.