1
template <class T>
class Stack
{
private:
    template <class L>
    class List
    {
    public:
        class Node
        {
        public:
            L data;
            Node* next;
        };
    Node* head;
};
    List<T> list;
public:
};

I want to create a variable of class Node in Stack class and I'm using this syntax

 List<T>::Node version;

But Visual Studio gives it at as syntax error. Please help me

  • Try `typename List::Node version;`. – songyuanyao Nov 10 '16 at 03:56
  • Thanks it worked But what it's use here ? #songyuanyao – Muddassir Nayyer Nov 10 '16 at 03:58
  • 3
    Possible duplicate of [Where and why do I have to put the "template" and "typename" keywords?](http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) –  Nov 10 '16 at 03:59
  • 1
    Because `List::Node` is dependent on template parameter `T`, the standards says we have to use `typename` to tell the compiler `List::Node` is a name of type (not other things like name of member). See the link posted by @NickyC for details. – songyuanyao Nov 10 '16 at 04:03

1 Answers1

0

As @songyuanyao said Try typename List<T>::Node version; to create a variable of class Node in Stack class

Real73
  • 490
  • 4
  • 13