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

Discussion in 'C++' started by an0, Dec 8, 2005.

  1. an0

    an0 Guest

    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?
    an0, Dec 8, 2005
    #1
    1. Advertising

  2. Re: Question Can I use explicit qualifier <C> after member functionname of a template class?

    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.
    Gianni Mariani, Dec 8, 2005
    #2
    1. Advertising

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

    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
    peter steiner, Dec 8, 2005
    #3
  4. an0

    an0 Guest

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

    I am sorry I have one typo in my first post.
    Thank you.
    an0, Dec 9, 2005
    #4
  5. an0

    bjarne Guest

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

    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
    bjarne, Dec 9, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ±ÇÌéÍõ×Ó
    Replies:
    7
    Views:
    792
  2. Replies:
    5
    Views:
    475
  3. Replies:
    9
    Views:
    443
    James Kanze
    Sep 9, 2007
  4. , India
    Replies:
    7
    Views:
    323
    James Kanze
    Apr 1, 2008
  5. Noah Roberts
    Replies:
    6
    Views:
    1,127
    Johannes Schaub (litb)
    Feb 2, 2011
Loading...

Share This Page