* RE: template(s) declaration with GCC3.2-7
[not found] <616BE6A276E3714788D2AC35C40CD18DC2AD0C@whale.softwire.co.uk>
@ 2003-04-22 16:44 ` Rupert Wood
0 siblings, 0 replies; 3+ messages in thread
From: Rupert Wood @ 2003-04-22 16:44 UTC (permalink / raw)
To: 'Rade Trimceski'; +Cc: gcc-help
Rade Trimceski wrote:
> 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.
:
> #include <list>
>
> template <class _Tp>
> class LsList : public list<_Tp> {
The newer C++ standards place the STL classes, list et al, inside the 'std'
namespace.
This means you can either address it in full:
class LsList : public std::list<_Tp> {
or import the elements you need from the std namespace:
#include <list>
using std::list;
or import the std namespace wholesale:
#include <list>
using namespace std;
In header files, I prefer the first since you're not polluting the global
namespace of source files that include the header. In C++ sources (.cpp,
.cc, etc.) I prefer the second form since it's more precise but lots just
use the third because it's simplest. But this is just a matter of style so
use whichever suits you.
Hope that helps,
Rup.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: template(s) declaration with GCC3.2-7
2003-04-22 16:34 Rade Trimceski
@ 2003-04-22 16:48 ` John Love-Jensen
0 siblings, 0 replies; 3+ messages in thread
From: John Love-Jensen @ 2003-04-22 16:48 UTC (permalink / raw)
To: Rade Trimceski, gcc-help
Have you tried...
Line 4: class LsList : public std::list<_Tp> {
...?
--Eljay
^ permalink raw reply [flat|nested] 3+ messages in thread
* template(s) declaration with GCC3.2-7
@ 2003-04-22 16:34 Rade Trimceski
2003-04-22 16:48 ` John Love-Jensen
0 siblings, 1 reply; 3+ messages in thread
From: Rade Trimceski @ 2003-04-22 16:34 UTC (permalink / raw)
To: gcc-help
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@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@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@Vaio tests]# g++ --version
g++ (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-04-22 16:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <616BE6A276E3714788D2AC35C40CD18DC2AD0C@whale.softwire.co.uk>
2003-04-22 16:44 ` template(s) declaration with GCC3.2-7 Rupert Wood
2003-04-22 16:34 Rade Trimceski
2003-04-22 16:48 ` John Love-Jensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).