Inherited members from templated class

  • Thread starter =?ISO-8859-1?Q?Xavier_D=E9coret?=
  • Start date
?

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

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.)
 
F

Fei Liu

Xavier said:
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.
 
V

Victor Bazarov

Fei said:
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.

Xavier:

Yes, it conforms.

V
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top