f



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

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?

0
an00na (3)
12/8/2005 5:07:51 AM
comp.lang.c++ 49423 articles. 5 followers. Post Follow

4 Replies
276 Views

Similar Articles

[PageSpeed] 56

an0 wrote:
> 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<class C> 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.

That appears to be the case.

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

I don't know.
0
gi2nospam (1236)
12/8/2005 6:38:36 AM
an0 wrote:
> 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

0
pnsteiner (49)
12/8/2005 9:58:54 AM
I am sorry I have one typo in my first post.
Thank you.

0
an00na (3)
12/9/2005 2:39:08 AM
peter steiner wrote:
> an0 wrote:
> > 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

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

0
bjarne (50)
12/9/2005 3:02:40 AM
Reply: