No type name ERROR

Hello, I'm having some issues with using templates with multiple classes.
Below I have my code. I have taken out most of it that is not causing any problems. I am getting "No Type Name 'valT' in 'list<char>' " it only happens for 4 functions 2 in class queue and class stack.

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
  #include <iostream>
  #include <iomanip>
  using namespace std;

/* classes */

template<typename valT>
class list {
    public:
        typedef int size_type;
        //Constructors
        list(){
        	my_array = new valT[CAPACITY];
        	ndx = pos = -1;
        	for(int i = 0; i < CAPACITY; i++)
            my_array[i] = nullVar;
		}
	
        list(list &L1){
        	ndx = L1.ndx;
    		pos = L1.pos;
    		my_array = new valT[CAPACITY];
    		for(int i = 0; i < CAPACITY; i++)
        	my_array[i] = L1.my_array[i];
    		CAPACITY = L1.CAPACITY;
		}
	
//set
        void insertBefore(valT value){
			if(ndx < CAPACITY && pos > ((CAPACITY - CAPACITY)-1)){
            	pos--;
            	insert(value);
        	}
		}
	
        void insertAfter(valT value){
        	 if(ndx < CAPACITY){
				pos++;
        		insert(value);
    		}
		}
        void insert(valT value){
        	my_array[pos] = value;
    		if(pos > ndx && pos <= CAPACITY)
        	ndx = pos;
		}
	
        void setPos(size_type set_position){
        	pos = set_position;
		}
	
        void replace(valT value){
        	my_array[pos] = value;
		}
//get
        bool empty(){
        	return (ndx == -1);
		}
        void first(){
        	pos = 0;
		}
        void last(){
        	pos = ndx;
		}
        void prev(){
        	if(pos > (CAPACITY- CAPACITY)-1) // if pos is -1 do not decrement
			pos--;
		}
        void next(){
        	if(pos < CAPACITY) // if pos is at capacity do not increment
			pos++;
		}
	
        size_type getPos(){
        	return pos;
		}
	
        valT getElement(){
        	return my_array[pos];
		}
	
        size_type   size(){
        	return ndx+1;
		}
	
        void erase(){
        //bumps pos to previous array location
        if(ndx != 0 && pos != ((CAPACITY - CAPACITY)-1)){
            for(int i = pos; i < ndx; i++)
            my_array[i] = my_array[i+1];
			}
			ndx--;
		}
	
        void clear(){
        	ndx = pos = -1; //resets values to out of bounds of array
		}
	
        list operator = (list &a){
        	pos = a.pos;
        	ndx = a.ndx;
        	CAPACITY = a.CAPACITY;
        	my_array = a.my_array;
    		for(int i = 0; i < CAPACITY; i++)
        		my_array[i] = a.my_array[i];
			return a;
		}
	
        bool operator == (list &a){
        	return (a.CAPACITY == CAPACITY && a.pos == pos && a.ndx == ndx);
		}
	
    private:
        valT nullVar = ' ';  // change to 0 if using int or float
        size_type CAPACITY = 200;
        valT* my_array;
        int pos;
        int ndx;
};

template<typename valT>
class stack{
    private:
    list<valT> myStack;
	
    public:
    void push(typename list<valT>::valT v){
    	myStack.last();
        myStack.insertAfter(v);
	}

    typename list<valT>::valT top(){
     	myStack.last();
        return myStack.getElement();
	}
};

template<typename valT>
class queue{
    private:
    list<valT> myQueue;
	
    public:
    void inqueue(typename list<valT>::valT v){
    	myQueue.last();
        myQueue.insertAfter(v);
	}

    typename list<valT>::valT front(){
    	myQueue.first();
        return myQueue.getElement();
	}
};





int main(){


stack<char> s;
queue<char> q;





return 0;
}


both functions in queue and stack class get errors

Thank you for your help
I think you just want
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
template<typename valT>
class stack
{
    private:
    list<valT> myStack;
  
    public:
    void push(valT v)
    {
      myStack.last();
      myStack.insertAfter(v);
    }

    valT top()
    {
      myStack.last();
      return myStack.getElement();
    }
};


and similarly for queue. The extra typenames caused the erorrs
That worked very well. How would I be able to write the function definition outside the class such as

//prototype
void push(valT v);



stack::push(valT v){
myStack.last();
myStack.insertAfter(v);
}

//something like this?
template<typename valT>
void stack<valT>::push(list<valT> v){
myStack.last();
myStack.insertAfter(v);
}
I'm not sure that's how you use templates, but you should try to use something else and update what's happening. This kind of errors might be hard to be detected when talking about bigger codes. It might spend a lot of time unless you have one of those programs, such as checkmarx, or practice a lot in order to avoid them. That happen with time and I'll sure you'll get there.
Good luck.
Topic archived. No new replies allowed.