Inherited members from templated class

Discussion in 'C++' started by =?ISO-8859-1?Q?Xavier_D=E9coret?=, Mar 7, 2006.

  1. I have just come across the following fact.

    Names defined in a template superclass of the current template must be
    qualified as being from the superclass. Alternatively, you can also
    qualify those names by preceding them with this->. An example might be
    clearer to read:


    template <typename T> struct Base
    {
    int m;
    };

    template <typename T> struct Derived : public Base<T>
    {
    void g()
    {
    m++; // ERROR: Name not found.

    this->m++; // OK
    Derived::m++; // OK
    Base<T>::m++; // OK
    }
    };


    This appears when migrating from gcc3 to gcc4 (see
    http://developer.apple.com/releasen...ortingReleaseNotes/Articles/PortingToGCC.html)
    ..

    My question is: is that conform to the standard (sorry to ask, but I am
    not familiar with reading through the standard. This might be trivial to
    answer for those who are.)
    =?ISO-8859-1?Q?Xavier_D=E9coret?=, Mar 7, 2006
    #1
    1. Advertising

  2. =?ISO-8859-1?Q?Xavier_D=E9coret?=

    novice Guest

    free c++ e-book

    Please tell me where i can get free e-book
    " Professional C++" wrox series
    novice, Mar 7, 2006
    #2
    1. Advertising

  3. =?ISO-8859-1?Q?Xavier_D=E9coret?=

    Ian Collins Guest

    Re: free c++ e-book

    novice wrote:
    > Please tell me where i can get free e-book
    > " Professional C++" wrox series
    >

    What makes you think it's free? Just buy it.

    --
    Ian Collins.
    Ian Collins, Mar 7, 2006
    #3
  4. =?ISO-8859-1?Q?Xavier_D=E9coret?=

    Fei Liu Guest

    Xavier Décoret wrote:
    > I have just come across the following fact.
    >
    > Names defined in a template superclass of the current template must be
    > qualified as being from the superclass. Alternatively, you can also
    > qualify those names by preceding them with this->. An example might be
    > clearer to read:
    >
    >
    > template <typename T> struct Base
    > {
    > int m;
    > };
    >
    > template <typename T> struct Derived : public Base<T>
    > {
    > void g()
    > {
    > m++; // ERROR: Name not found.

    This doesn't seem right. struct members are implicitly declared public
    by default thus accessible in derived class. Post your complete code
    please.
    >
    > this->m++; // OK
    > Derived::m++; // OK
    > Base<T>::m++; // OK
    > }
    > };
    >
    >
    > This appears when migrating from gcc3 to gcc4 (see
    > http://developer.apple.com/releasen...ortingReleaseNotes/Articles/PortingToGCC.html)
    > .
    >
    > My question is: is that conform to the standard (sorry to ask, but I am
    > not familiar with reading through the standard. This might be trivial to
    > answer for those who are.)
    Fei Liu, Mar 7, 2006
    #4
  5. Fei Liu wrote:
    > Xavier Décoret wrote:
    >
    >>I have just come across the following fact.
    >>
    >>Names defined in a template superclass of the current template must be
    >>qualified as being from the superclass. Alternatively, you can also
    >>qualify those names by preceding them with this->. An example might be
    >>clearer to read:
    >>
    >>
    >>template <typename T> struct Base
    >>{
    >> int m;
    >>};
    >>
    >>template <typename T> struct Derived : public Base<T>
    >>{
    >> void g()
    >> {
    >> m++; // ERROR: Name not found.

    >
    > This doesn't seem right. struct members are implicitly declared public
    > by default thus accessible in derived class. Post your complete code
    > please.


    Read about "dependent names" in the FAQ.

    >
    >> this->m++; // OK
    >> Derived::m++; // OK
    >> Base<T>::m++; // OK
    >> }
    >>};
    >>
    >>
    >>This appears when migrating from gcc3 to gcc4 (see
    >>http://developer.apple.com/releasen...ortingReleaseNotes/Articles/PortingToGCC.html)
    >>.
    >>
    >>My question is: is that conform to the standard (sorry to ask, but I am
    >>not familiar with reading through the standard. This might be trivial to
    >>answer for those who are.)


    Xavier:

    Yes, it conforms.

    V
    --
    Please remove capital As from my address when replying by mail
    Victor Bazarov, Mar 7, 2006
    #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. lovecreatesbeauty
    Replies:
    43
    Views:
    1,285
    Keith Thompson
    Feb 6, 2006
  2. lovecreatesbeauty
    Replies:
    2
    Views:
    576
  3. Replies:
    1
    Views:
    284
    Sumit Rajan
    Feb 7, 2007
  4. chhenning
    Replies:
    5
    Views:
    352
    chhenning
    Feb 13, 2008
  5. 7stud --
    Replies:
    11
    Views:
    386
    7stud --
    Nov 9, 2007
Loading...

Share This Page