Redefinition of 'Linked Stack' as different kind of symbol

I am confused as to why it says I am redefining class LinkedStack on line 14 when I haven't defined it yet. When I remove template <typename T> on line 13, the error goes away. The error also goes away when I remove friend class LinkedStack on line 10. I don't understand why I'm getting this error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
using namespace std;

template <typename T>
class Node
{
private:
    T elem;
    Node* next;
    friend class LinkedStack;
};

template <typename T>
class LinkedStack  //error: redefinition of 'LinkedStack' as different kind of symbol
{
public:
    LinkedStack();          //constructor
    int size() const;       //size of stack
    bool empty() const;     //is stack empty?
    void push(const T&);    //push function
    void pop();             //pop function
    const T& top();         //return reference of top
private:
    Node* top;
};

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
template < typename T > class LinkedStack ; // declare class template LinkedStack

template < typename T > class Node
{
    // ...
    friend class LinkedStack<T> ; // note: <T>
};

template < typename T > class LinkedStack
{
    public:

        // ...

    private: Node<T>* top; // note: <T>
};
Thank you very much.
Topic archived. No new replies allowed.