Template disambiguation

J

John Collins

I just tried to build under GNU C++ 3.4.1 and then 3.4.3 a program which was
working fine under G++ 3.3.*

It uses template members "shm_cast" to obtain a pointer "foo *" to a
structure in shared memory from an offset "off" thus

template<typename T> T *shm_cast(const shmoff_t off) const
{
return static_cast<T*>(shmp(off));
}

used thus:

foo *item = seg.template shm_cast<foo>(off);

This is according to Stroustrup Appendix C13.6

If "template" is left out there it doesn't parse it right as was the case in
G++ 3.3.*.

It works fine with 3.3.* but with G++ 3.4.* it reports

error: `template' (as a disambiguator) is only allowed within templates

Please can anyone advise if G++ 3.4.* is broken or has some different syntax
been coined for this I haven't heard about.

Thanks if anyone can help.
 
V

Victor Bazarov

John Collins said:
I just tried to build under GNU C++ 3.4.1 and then 3.4.3 a program which
was
working fine under G++ 3.3.*

It uses template members "shm_cast" to obtain a pointer "foo *" to a
structure in shared memory from an offset "off" thus

template<typename T> T *shm_cast(const shmoff_t off) const
{
return static_cast<T*>(shmp(off));
}

used thus:

foo *item = seg.template shm_cast<foo>(off);

This is according to Stroustrup Appendix C13.6

If "template" is left out there it doesn't parse it right as was the case
in
G++ 3.3.*.

It works fine with 3.3.* but with G++ 3.4.* it reports

error: `template' (as a disambiguator) is only allowed within templates

Please can anyone advise if G++ 3.4.* is broken or has some different
syntax
been coined for this I haven't heard about.


Please post _complete_ code that can be run through a compiler.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top