This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
template(s) declaration with GCC3.2-7
- From: Rade Trimceski <rtrimces at mtu dot edu>
- To: gcc-help at gcc dot gnu dot org
- Date: 22 Apr 2003 12:33:57 -0400
- Subject: template(s) declaration with GCC3.2-7
- Organization:
Hey guys (and girls if there are any) :)
I'm trying to compile code that was written a while ago, and compiled
just fine with gcc 2.96. GCC 3.2-7 doesn't like it at all. Here's the
code as I extracted it from the header file:
[rtrimces at Vaio tests]#cat template_test.cpp
#include <list>
template <class _Tp>
class LsList : public list<_Tp> {
public:
typedef list<_Tp> baseList;
LsList() : baseList() {}
LsList(const _Tp& x) : baseList(1, x) {}
void eraseAll() {
baseList::erase(begin(), end());
}
LsList<_Tp>& operator= (const LsList<_Tp> & x) {
return (LsList<_Tp> &)baseList::operator= (x);
}
};
When trying to compile I get the following errors:
[rtrimces at Vaio tests]# g++ -o template.o template_test.cpp
template_test.cpp:4: parse error before `<' token
template_test.cpp:7: ISO C++ forbids declaration of `LsList' with no
type
template_test.cpp: In function `int LsList()':
template_test.cpp:7: `int LsList()' redeclared as different kind of
symbol
template_test.cpp:4: previous declaration of `template<class _Tp> class
LsList'
template_test.cpp:4: previous non-function declaration `template<class
_Tp>
class LsList'
template_test.cpp:7: conflicts with function declaration `int LsList()'
template_test.cpp:7: only constructors take base initializers
template_test.cpp:7: confused by earlier errors, bailing out
Can someone tell me what has changed with the compiler and why this code
doesn't compile anymore? Even better answer would be how should I write
this code in order to make it compile with gcc 3.2.
Thanks a lot!
Rade
P.S.
In case you are wondering:
[rtrimces at Vaio tests]# g++ --version
g++ (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)