This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
GCC Template bug or my bad?
- From: Jeroen Benckhuijsen <jeroen at themindconnection dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 03 Sep 2003 21:10:43 +0200
- Subject: GCC Template bug or my bad?
Hi,
I'm working on a project, originaly build on windows, and i'm now trying
to compile it using gcc/linux. The whole project is written in ANSI C++
(afaik), so apart from some Win32 API calls, it "should" compile. The
following piece of code produces an error, although i think it's correct
C++ (or am i wrong). I've checked to docs of gcc, but couldn't find any
pointers...
template <class T>
bool
SharedMemory::pget (T& n) const
{
const unsigned long tsize = sizeof(T);
if (_pos + tsize > _memory->Size()) {
return false;
}
char* p = _memory->Pointer<char*>() + _pos; /***** ERROR ****/
T* q = (T*)(p);
n = *q;
_pos += tsize;
return true;
}
where the template method is defined as
class ShMemory {
public:
/* snip: some boring stuff */
template <class T>
T Pointer ()
{
return static_cast<T>(_Pointer());
}
/* snip some other boring stuff */
};
The error:
SharedMemory.cpp: In member function `bool SharedMemory::pget(T&) const':
SharedMemory.cpp:109: parse error before `*' token
The code compiles without any problems in Visual C++ 2003 (which isn't a
garantee for correctness off course..). The same error happens in every
situation with template method specialization. My first guess was a bad
on my side, but after checking Stroustroup's "The C++ Programming
language", i couldn't find anything pointing to an error on my side. Any
hints?
Jeroen