DEVELOP > c-Plus-Plus > Question Can I use explicit qualifier after member function name of a template class?
| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"an0" |
| Date: |
07 Dec 2005 11:07:51 PM |
| Object: |
Question Can I use explicit qualifier 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?
.
|
|
| User: "peter steiner" |
|
| Title: Re: Question Can I use explicit qualifier after member function name of a template class? |
08 Dec 2005 03:58:54 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
.
|
|
|
| User: "an0" |
|
| Title: Re: Question Can I use explicit qualifier after member function name of a template class? |
08 Dec 2005 08:39:08 PM |
|
|
I am sorry I have one typo in my first post.
Thank you.
.
|
|
|
|
| User: "bjarne" |
|
| Title: Re: Question Can I use explicit qualifier after member function name of a template class? |
08 Dec 2005 09:02:40 PM |
|
|
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
.
|
|
|
|
|
| User: "Gianni Mariani" |
|
| Title: Re: Question Can I use explicit qualifier after member functionname of a template class? |
08 Dec 2005 12: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> () { /*...*/ }"
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.
.
|
|
|
|

|
Related Articles |
|
|