Re: Error compiling in g++ 4.1 and 4.3 (template and typedef)
afcmoraesf@gmail.com schrieb:
Hi,
I'm getting the error
main.C: In constructor ?Test<T>::Test(T, T, T)?:
main.C:19: error: expected `;' before ?it?
compiling the code
=======BEGIN
#include <iostream>
#include <list>
#include <string>
template<class T> class Test
{
public:
typedef std::list<T> T_LIST;
Test(T a1, T a2, T a3);
};
template<class T> Test<T>::Test(T a1, T a2, T a3)
{
T_LIST t_list;
t_list.push_front(a1);
t_list.push_front(a2);
t_list.push_front(a3);
T_LIST::iterator it;
for ( it = t_list.begin() ; it != t_list.end() ; it++ )
std::cout << *it << std::endl;
}
int main(int argc, char** argv)
{
Test<int> test(1, 2, 3);
}
=====END
what's wrong ?
Thanks,
Antonio
gcc 4.3.2 complains;
t1.cpp: In constructor ?Test<T>::Test(T, T, T)?:
t1.cpp:19: error: expected `;' before ?it?
t1.cpp:21: error: ?it? was not declared in this scope
t1.cpp: In constructor ?Test<T>::Test(T, T, T) [with T = int]?:
t1.cpp:28: instantiated from here
t1.cpp:19: error: dependent-name ?std::list::iterator? is parsed as a
non-type, but instantiation yields a type
t1.cpp:19: note: say ?typename std::list::iterator? if a type is meant
So, inserting "typemname" in fornt of line 19 does the job.
Lars
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]