By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

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

P: n/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?

Dec 8 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.
Dec 8 '05 #2

P: n/a
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

Dec 8 '05 #3

P: n/a
an0
I am sorry I have one typo in my first post.
Thank you.

Dec 9 '05 #4

P: n/a

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/WG...fects.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

Dec 9 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.