I am not sure why I am getting these error messages

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

mingw32-g++.exe   -c C:\Martin\MalikChapter7\programmingExercise1.cpp -o C:\Martin\MalikChapter7\programmingExercise1.o
C:\Martin\MalikChapter7\programmingExercise1.cpp:25:11: error: declaration of 'class T'
 template <class T> T  Stack<T>::Pop( )
           ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:10:11: error:  shadows template parm 'class T'
 template <class T> class Stack {
           ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:25:38: error: invalid use of incomplete type 'class Stack<T>'
 template <class T> T  Stack<T>::Pop( )
                                      ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:10:26: note: declaration of 'class Stack<T>'
 template <class T> class Stack {
                          ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:35:12: error: declaration of 'class T'
  template <class T> bool Stack<T>::Empty( )
            ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:10:11: error:  shadows template parm 'class T'
 template <class T> class Stack {
           ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:35:43: error: invalid use of incomplete type 'class Stack<T>'
  template <class T> bool Stack<T>::Empty( )
                                           ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:10:26: note: declaration of 'class Stack<T>'
 template <class T> class Stack {
                          ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:39:11: error: declaration of 'class T'
 template <class T> void Stack<T>::Push(T item)
           ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:10:11: error:  shadows template parm 'class T'
 template <class T> class Stack {
           ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:39:46: error: invalid use of incomplete type 'class Stack<T>'
 template <class T> void Stack<T>::Push(T item)
                                              ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:10:26: note: declaration of 'class Stack<T>'
 template <class T> class Stack {
                          ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:48:10: error: declaration of 'class T'
 template<class T>Stack<T>::Stack()
          ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:10:11: error:  shadows template parm 'class T'
 template <class T> class Stack {
           ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:48:34: error: invalid use of incomplete type 'class Stack<T>'
 template<class T>Stack<T>::Stack()
                                  ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:10:26: note: declaration of 'class Stack<T>'
 template <class T> class Stack {
                          ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:53:11: error: declaration of 'class T'
 template <class T> stack <T> :: Stack (const Stack <T> & S):
           ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:10:11: error:  shadows template parm 'class T'
 template <class T> class Stack {
           ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:53:59: error: invalid use of incomplete type 'class std::stack<T>'
 template <class T> stack <T> :: Stack (const Stack <T> & S):
                                                           ^
In file included from C:/CodeBlock/CodeBlocks/MinGW/lib/gcc/mingw32/5.1.0/include/c++/stack:61:0,
                 from C:\Martin\MalikChapter7\programmingExercise1.cpp:2:
C:/CodeBlock/CodeBlocks/MinGW/lib/gcc/mingw32/5.1.0/include/c++/bits/stl_stack.h:99:11: note: declaration of 'class std::stack<T>'
     class stack
           ^
C:\Martin\MalikChapter7\programmingExercise1.cpp:82:1: error: expected '}' at end of input
 }
 ^
C:\Martin\MalikChapter7\programmingExercise1.cpp: In member function 'int Stack<T>::main()':
C:\Martin\MalikChapter7\programmingExercise1.cpp:78:33: error: expected ';' before string constant
         cout <<otherStack.top() " ";
                                 ^
C:\Martin\MalikChapter7\programmingExercise1.cpp: At global scope:
C:\Martin\MalikChapter7\programmingExercise1.cpp:82:1: error: expected unqualified-id at end of input
 }
 ^
Process terminated with status 1 (0 minute(s), 0 second(s))
18 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 


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
       void Push (T item);
        T Pop ();
        bool Empty ();
        Stack &operator = (const Stack<T> & S); // assignment
        Stack *top;
   private:
        struct StackNode {
            T data;
            StackNode *next;
 };
template <class T> T  Stack<T>::Pop( )
{
    T retval;
    StackNode *tmp = top;
    assert(!Empty());
    retval = top->data;
    top = top->next;
    delete tmp;
    return (retval);
}
 template <class T> bool Stack<T>::Empty( )
        {
           return (NULL == top);
        }

     
Your indentation is misleading. Line 10 ends the definition of Stack<T>::StackNode. You need another pair of }; to end the definition of Stack<T> before you can define Stack<T>::Pop() and Stack<T>::Empty().
Last edited on
Sorry not everything went through.
Here it is:
[code]
#include<iostream>
#include<cassert>
#include<stack>
template <class T> class Stack{
public:
Stack();
Stack(const Stack<T>&S ; //copy constructor
~Stack();
void Push(T item);
Stack &operator=(const Stack<T>&S);
Stack *top;
private:
struct StackNode
{
T data;
StackNode *next;
};
template <class T> T Stack<T>::Pop( )
{
.
.
.
}
After that line, everywhere where the word:
template<class T> appears the error of shadowing comes up.

Sorry My mouse is not working well today so I battle to post the rest of the code.
I then get the errors posted above

template<class T>
Topic archived. No new replies allowed.