Question Can I use explicit qualifier <C> after member function name of a template class?

A

an0

Bjarne Stroustrup's "The C++ Language Programming" says at P330:
"Within the scope of String<C>, qualification with <C> is redundant for
the name of the template itself, so String<C>::String is the name for
the constructor. If you prefer, you can be explicit:
template<class T> String<C>: String<C> () { /*...*/ }"

But in fact, I find I cannot use this 'explicit' form for any member
function of a template class with g++ or Comeau.

Is it the problem of the compilers or the book?
 
G

Gianni Mariani

an0 said:
Bjarne Stroustrup's "The C++ Language Programming" says at P330:
"Within the scope of String<C>, qualification with <C> is redundant for
the name of the template itself, so String<C>::String is the name for
the constructor. If you prefer, you can be explicit:
template<class T> String<C>: String<C> () { /*...*/ }"

I suspect you mean:

template said:
But in fact, I find I cannot use this 'explicit' form for any member
function of a template class with g++ or Comeau.

That appears to be the case.
Is it the problem of the compilers or the book?

I don't know.
 
P

peter steiner

an0 said:
Bjarne Stroustrup's "The C++ Language Programming" says at P330:
"Within the scope of String<C>, qualification with <C> is redundant for
the name of the template itself, so String<C>::String is the name for
the constructor. If you prefer, you can be explicit:
template<class T> String<C>: String<C> () { /*...*/ }"

But in fact, I find I cannot use this 'explicit' form for any member
function of a template class with g++ or Comeau.

Is it the problem of the compilers or the book?

you should get yourself a copy of the c++03 standard, as this is the
definitive instance for questions like this. otherwise have a look at
stroustrup's homepage, it features an errata for tc++pl, maybe your
revision is outdated or stands corrected.

i don't think that this is mentioned anywhere in the standard (surely
not 14.5.1 class templates)... so while not sure i suspect the book is
at fault...

-- peter
 
B

bjarne

peter said:
you should get yourself a copy of the c++03 standard, as this is the
definitive instance for questions like this. otherwise have a look at
stroustrup's homepage, it features an errata for tc++pl, maybe your
revision is outdated or stands corrected.

i don't think that this is mentioned anywhere in the standard (surely
not 14.5.1 class templates)... so while not sure i suspect the book is
at fault...

-- peter

I suspect not.

template<class T> String<C>: String<C> () { /*...*/ }" is valid
according to

http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#147

There is a PR against GCC for bugs in not correctly handling the
injected-name rules. I believe it is still not fixed.

-- Bjarne Stroustrup; http://www.research.att.com/~bs
 

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

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top