Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Inherited members from templated class

Reply
Thread Tools

Inherited members from templated class

 
 
=?ISO-8859-1?Q?Xavier_D=E9coret?=
Guest
Posts: n/a
 
      03-07-2006
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/releaseno...tingToGCC.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.)
 
Reply With Quote
 
 
 
 
novice
Guest
Posts: n/a
 
      03-07-2006
Please tell me where i can get free e-book
" Professional C++" wrox series

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      03-07-2006
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.
 
Reply With Quote
 
Fei Liu
Guest
Posts: n/a
 
      03-07-2006

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/releaseno...tingToGCC.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.)


 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      03-07-2006
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/releaseno...tingToGCC.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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining templated member function outside templated class chhenning C++ 5 02-13-2008 07:36 PM
'Class.inherited' v. 'inherited' syntax inside Class 7stud -- Ruby 11 11-09-2007 06:45 PM
Inherited members of templated classes cpunerd@gmail.com C++ 1 02-07-2007 06:11 AM
Which members are created automatically, which members are not inherited? lovecreatesbeauty C Programming 43 02-06-2006 11:36 PM
Which members are created automatically, which members are not inherited? lovecreatesbeauty C++ 2 01-26-2006 06:03 PM



Advertisments