template'y i blad: dependent-name is parsed as a non-type

0

Napisałem:

template <class T>
T minVecCol(list<list<T> > lista, short int col) {
	T	ret = 10e7;
	list<T>	v;
	list<list<T> >::iterator	vit;	// iterator po wektorach (line 278)
	list<T>::iterator		cit;	// iterator po kolumnach (line 279)
	vit = lista.begin();
	for (; vit!=lista.end(); vit++) {
		v = *vit;
		cit = v.begin();
		advance(cit, col-1);
		if (ret>*cit)	ret=*cit;
	}
	return ret;
}

i przy kompilacji są błędy:

g.cpp: In function 'T minVecCol(std::list<std::list<T, std::allocator<_CharT> >, std::allocator<std::list<T, std::allocator<_CharT> > > >, short int)':
g.cpp error: expected ;' before 'vit' g.cpp:279: error: expected ;' before 'cit'
g.cpp error: 'vit' was not declared in this scope
g.cpp error: 'cit' was not declared in this scope
g.cpp: In function 'T minVecCol(std::list<std::list<T, std::allocator<_CharT> >, std::allocator<std::list<T, std::allocator<_CharT> > > >, short int) [with T = double]':
g.cpp instantiated from here
g.cpp error: dependent-name 'std::list<std::list<T, std::allocator<_CharT> >,std::allocator<std::list<T, std::allocator<_CharT> > > >::iterator' is parsed as a non-type, but instantiation yields a type
g.cpp note: say 'typename std::list<std::list<T, std::allocator<_CharT> >,std::allocator<std::list<T, std::allocator<_CharT> > > >::iterator' if a type is meant
g.cpp error: dependent-name 'std::list<T,std::allocator<_CharT> >::iterator' is parsed as a non-type, but instantiation yields a type
g.cpp note: say 'typename std::list<T,std::allocator<_CharT> >::iterator' if a type is meant
make: *** [g.o] Błąd 1
Co powinienem poprawić? (Pierwszy raz chcę skorzystać z template'ów.) :-|

0

po pierwsze:
typename list<list<T> >::iterator vit; // iterator po wektorach (line 278)
typename list<T>::iterator cit; // iterator po kolumnach (line 279

nie wdajac sie w zbytnie szczegoly - nie ma takiego typu danych jak 'list<T>::iterator' ani 'list<list<T>>::iterator'. sa to jedynie instrukcje jak wygenerowac wlasciwa nazwe typu, dlatego trzeba je specjalnie oznaczyc zeby kompilator od razu wiedzial ze to jest to przetworzenia a nie szukal takiej konkretnej nazwy

0

To rozwiązało wszystkie błędy. Dzięki! :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1