1

just tell me why it is not possible to use struct of template class in another template class. i personally think it is logical. have c++ such feature? I'm using VS 2015. thanks :)

template<typename T> class MyList
{
public:
    struct Node
    {
        T       value;
        Node*   next;
    };
    //...
};

template<typename Type> class MyMap
{
public:
    struct ElementData
    {
        Type        types[32];
        unsigned    key;
    };

    MyList<ElementData>::Node* nodes;   //Syntax Error: Identifier 'Node'
};

while this works.

template <typename T> struct Node
{
    T       value;
    Node*   next;
};

template<typename T> class MyList
{
public:
    Node<T>* root;
    //...
};

template<typename Type> class MyMap
{
public:
    struct ElementData
    {
        Type        types[32];
        unsigned    key;
    };

    Node<ElementData>* nodes;   
};
Danesh
  • 13
  • 5

1 Answers1

1

You need to add typename (for dependent type name MyList<ElementData>::Node) here,

typename MyList<ElementData>::Node* nodes;

Inside a declaration or a definition of a template, typename can be used to declare that a dependent name is a type.

See Where and why do I have to put the “template” and “typename” keywords?

Community
  • 1
  • 1
songyuanyao
  • 169,198
  • 16
  • 310
  • 405