No class template named 'x' in 'y'

When i try to compile code with TDM-GCC 4.9.2 64 bit realease i get:
[Error] no class template named 'Linear_list_ord' in 'class Linear_list<std::basic_string<char>, List_node<std::basic_string<char> >*>' at line 65 of Linked_list_ord.h

Here is Linked_list_ord.h

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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#ifndef _LINKED_LIST_ORD_H
#define _LINKED_LIST_ORD_H

#include "Linear_list_ord.h"

template<class T>
class Linked_list_ord;

template< class T >
class List_node{
	friend class Linked_list_ord<T>;
 private:
	T _value;
	List_node<T> * _pPrev;
	List_node<T> * _pNext;
};




template< class T >
class Linked_list_ord : public Linear_list_ord<T, List_node<T>*>{
 public:
	typedef typename Linear_list_ord<T, List_node<T>*>::value_type value_type;
	typedef typename Linear_list_ord<T, List_node<T>*>::position position;

	// costruttori
	Linked_list_ord();
	Linked_list_ord(int);
	// costruttore per copia
	Linked_list_ord(const Linked_list_ord<T>& );
	//distruttore
	~Linked_list_ord();

	// operatori
	void create();
	bool empty() const;
	value_type read(position) const;
	void write(const value_type &, position);
	position begin() const;
	position last() const;
	bool end(position) const;
	position next(position) const;
	position previous(position) const;
	void erase(position);
	void insert (const value_type &);
	void fondi(const Linked_list_ord<T> &);
	bool isPalindroma();
	
	
	int size() const {
		return _length;
	}

	// sovraccarico di operatori
	Linked_list_ord<T>& operator=(const Linked_list_ord<T>&); // the assignment operator
	bool operator==(const Linked_list_ord<T> &) const; // tests two list for equality

 private:
	List_node<T> * _pHead;
	int & _length = Linear_list<T,List_node<T>*>::template Linear_list_ord<T, List_node<T>*>::_length;
};

template< class T >
Linked_list_ord<T>::Linked_list_ord() {
	_pHead = new List_node<T>;
	_pHead->_pNext = _pHead;
	_pHead->_pPrev = _pHead;
	_length = 0;
}


template< class T >
Linked_list_ord< T >::Linked_list_ord(const Linked_list_ord<T>& L) {
  _length = L.size();

	_pHead = new List_node<T>;
	_pHead->_pNext = _pHead;
	_pHead->_pPrev = _pHead;

	if (!L.empty()){
		position p = L.last();
		for (int i=0; i <= L._length; i++){
			insert(L.read(p), begin());
			p = L.previous(p);
		}
	}
}


template< class T >
Linked_list_ord< T >::~Linked_list_ord(){
	while(!empty())
		erase(begin());
	delete _pHead;
}

template< class T >
void Linked_list_ord< T >::create(){
	if (empty())
			_length = 0;
}

template< class T >
bool Linked_list_ord< T >::empty() const {
	return(_pHead == _pHead->_pNext);
}

template< class T >
typename Linked_list_ord< T >::position
Linked_list_ord< T >::begin() const {
	return (_pHead->_pNext);
}

template< class T >
typename Linked_list_ord< T >::position
Linked_list_ord< T >::last() const {
	return (_pHead->_pPrev);
}


template< class T >
typename Linked_list_ord< T >::position
Linked_list_ord< T >::next(position p) const {
	return(p->_pNext);
}

template< class T >
typename Linked_list_ord< T >::position Linked_list_ord< T >::previous(position p) const {
	if (p != _pHead)
		return(p->_pPrev);
}

template< class T >
bool Linked_list_ord< T >::end(position p) const {
	return(p == _pHead);
}

template< class T >
typename Linked_list_ord< T >::value_type
Linked_list_ord< T >::read(position p) const {
	if (!end(p))
		return(p->_value);
}

template< class T >
void Linked_list_ord< T >::write(const value_type &a, position p) {
	if (!end(p))
    p->_value = a;
}

template< class T >
void Linked_list_ord<T>::insert(const value_type &a){
	position p = begin();
	position t = new List_node<value_type>;
	t->_value = a;
	
	while(a<read(p) && (!end(p)))
		p=next(p);
	t->_pNext = p;
	t->_pPrev = p->_pPrev;
	p->_pPrev->_pNext = t;
	p->_pPrev = t;

	_length++;
}

template< class T >
void Linked_list_ord< T >::erase(position p){
	if (!empty() && !end(p)){
		p->_pPrev->_pNext = p->_pNext;
		p->_pNext->_pPrev = p->_pPrev;
		delete p;
	}
}


template<class T>
Linked_list_ord<T>& Linked_list_ord<T>::operator=(const Linked_list_ord<T>& L){
	if (this != &L){
		_length = L.size();

		_pHead = new List_node<T>;
		_pHead->_pNext = _pHead;
		_pHead->_pPrev = _pHead;

        cout << L.empty();
        cout << L.size();
		if (!L.empty()){
            position p = L.last();
			for (int i=0; i < L.size(); i++){
				cout << i, L.read(p);
				insert(L.read(p), begin());
				p = L.previous(p);
			}
		}
	}
	return *this;
}

template<class T>
bool Linked_list_ord<T>::operator==(const Linked_list_ord<T> &L) const{
	if (L.size() != _length)
		return false;
	position p, pL;
	p = begin();
	pL = L.begin();
	while (!end(p)){
		if (p->_value != pL->_value)
			return false;
		p = p->_pNext;
		pL = pL->_pNext;
	}
	return true;
}

template <class T>
void Linked_list_ord<T>::fondi (const Linked_list_ord<T> &L) {
	Linked_list_ord<T>::position PL =L.begin();
	while(!L.end(PL)) {
		insert(L.read(PL));
		PL = L.next(PL);
	}
	
}

template <class T>
bool Linked_list_ord<T>::isPalindroma () {
	Linked_list_ord<T>::position PL =next(begin());
	while(!end(PL)) {
		if(read(previous(PL)!=read(PL))) return false;
	}
	return true;
	
}

#endif // _LINKED_LIST_H 


Here is Linear_list_ord.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef _LINEARLISTORD_H
#define _LINEARLISTORD_H

#include "Linear_list.h"


template< class T, class P >
class Linear_list_ord : public Linear_list<T,P> {
public:
	typedef typename Linear_list<T,P>::value_type value_type;
	typedef typename Linear_list<T,P>::position position;
	virtual void insert (const value_type &) = 0;
};

#endif // _LISTALIN_H 


Linear_list.h

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
#ifndef _LISTALIN_H
#define _LISTALIN_H

#include <iostream>

using std::cout;
using std::endl;
using std::ostream;

// classe astratta listaLinare
template< class T, class P >
class Linear_list{
 public:
	typedef T value_type;   // the type of object, T, stored in the list
	typedef P position;
	
	// operators
	virtual void create() = 0;
	virtual bool empty() const = 0; // true if the list's size is 0
	virtual value_type read(position) const = 0;
	virtual void write(const value_type & x, position p) = 0; // write x at position p
	virtual position begin() const = 0;  // returns a position pointing to the beginning of the list
	virtual bool end(position) const = 0; // true with a position pointing to the end of the list
	virtual position next(position) const = 0; // returns the next position
	virtual position previous(position) const = 0; // return the previous position
	virtual void erase(position) = 0;

	// funzioni di servizio
	//friend ostream& operator<< <T,P>(ostream&, const Linear_list<T,P>&);

	/* Altre funzioni di servizio implementabili */
	/*
		virtual int size() const;  // returns the size of the list
		virtual void push_front(const value_type &); // insert a new element at the beginning
		virtual void push_back(const value_type &); // insert a new element at the end
		virtual void pop_front(); // removes the first element
		virtual void pop_back(); // removes the last element
		virtual void clear(); // erases all the elements
	*/
	
	 int lunghezza() {
		return _length;
			}

	position last() {
		position p = begin();
			int i=0;
		while(i<lunghezza()) {
			p = next(p);
			i++; 
			} 
	}
	 void inverti(){
		position l = begin();
		position r = last();
		value_type temp;
		int i=0;

		while(i<lunghezza()/2) {
			temp = read(l);
			write(read(r),l);
			write(temp,r);
			l=next(l);
			r=previous(r);
			i++;
			}
	}
	
		bool isPalindroma(){
		position l = begin();
		position r = last();
		bool palindroma = true;
		value_type temp;

		int i=0;
		while(i<lunghezza()/2 && palindroma) {
			palindroma = read(l)==read(r);
			l=next(l);
			r=previous(r);
			i++;
			}
		return palindroma;
	}
	 protected:
		int _length;
};
/* sovraccarica <<. Attenzione se il tipo restituito da read non è primitivo, allora
 * anche per questo tipo bisogna sovraccaricare l'operatore << 
 */
template< class T, class P >
ostream& operator<<(ostream& os, const Linear_list<T,P> &l){
	typename Linear_list<T,P>::position p;
	p = l.begin();
	os << "[";
	while (!l.end(p)){
		if (p != l.begin())
			os << ", " << l.read(p);
		else
			os << l.read(p);
		p = l.next(p);
	}
	os << "]" << endl;
	return os;
}

/*
template< class T, class P >
int Linear_list<T,P>::size() const{
   ....
}
*/

#endif // _LISTALIN_H  


And main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Linked_list_ord.h"
#include <stdlib.h>
#include <iostream>
#include <string>

int main () {
	
	Linked_list_ord<std::string> bello ;
	
	bello.insert("hello");
	  
	return 0;
	}
Last edited on
1
2
//int & _length = Linear_list<T,List_node<T>*>::template Linear_list_ord<T, List_node<T>*>::_length;
int & _length = Linear_list_ord<T, List_node<T>*>::_length;
¿what's the idea? ¿why make the reference instead of accessing it directly (or using the interface)?
I wanted to simplify the name
It seems this could do the trick:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
template< class T, class P >
class Linear_list_ord : public Linear_list<T,P> {
public:
    . . .
protected:
    using Linear_list<T, P>::_length; // <-- added
};

template< class T >
class Linked_list_ord : public Linear_list_ord<T, List_node<T>*> {
public:
    . . .
private:
    List_node<T> * _pHead;
    // removed:
    int & _length = Linear_list<T,List_node<T>*>::template Linear_list_ord<T, List_node<T>*>::_length;
    using Linear_list_ord<T, List_node<T>*>::_length; // <-- added
};


Anyway you’d better comment out this instruction inside main():
bello.insert("hello");
since your insert() method causes the program to crash.
Thnak you, it worked
Topic archived. No new replies allowed.