GCC Template bug or my bad?
Jeroen Benckhuijsen
jeroen@themindconnection.com
Wed Sep 3 19:09:00 GMT 2003
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
More information about the Gcc-bugs
mailing list