473,785 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inherited members from templated class

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.)
Mar 7 '06 #1
4 1703
Please tell me where i can get free e-book
" Professional C++" wrox series

Mar 7 '06 #2
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.
Mar 7 '06 #3

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


Mar 7 '06 #4
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
Mar 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1868
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
6
1771
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that the individual elements in an array of ImageList's could be identified by the ID, thereby allowing re-ordering the array without harm. A person could identify by index into the array, but that would not be preserved by re-ordering (and re-ordering...
2
2982
by: lovecreatesbeauty | last post by:
I'm disturbed on this question on a long time. I think if I finally get understand it with your kind help, I will get close to a excellent C++ programmer. And I only can rely on your expertise and help. I've read some books, but no book focuses on this. Don't you think it is a very important thing of C++ programming language? So your knowledge is of great benefit to others, especially me. 1. Which (How many) members will be created...
2
2828
by: Amadeus W. M. | last post by:
Template member functions cannot be virtual - I know - but is there any way to simulate that (other than making the entire class templated, with non-templated members). What I have is this: class Transform { public:
14
2644
by: lovecreatesbea... | last post by:
Could you tell me how many class members the C++ language synthesizes for a class type? Which members in a class aren't derived from parent classes? I have read the book The C++ Programming Language, but there isn't a detail and complete description on all the class members, aren't they important to class composing? Could you explain the special class behavior in detail? Thank you very much.
1
1494
by: cpunerd | last post by:
Hello, I'm not new to C++, but for some reason, until now I'd never had a need for deriving templated classes. Now though, I find myself seeing a weird problem. If I have a templated base class (Base), and a template derived class (Derived, which is publicly inherited from Base with the same template parameters), why must I prefix all "Base" member accesses in "Derived" with Base<template arguments>? Is there perhaps another method that...
21
2216
by: George Exarchakos | last post by:
Hi everyone, I'd like your help... Can we have a std::list<BASEwhere BASE be the base class of a class hierarchy? I want to add to this list objects that are inherited from BASE class but not necessarily the same... class base { int x;
19
2236
by: jan.loucka | last post by:
Hi, We're building a mapping application and inside we're using open source dll called MapServer. This dll uses object model that has quite a few classes. In our app we however need to little bit modify come of the classes so they match our purpose better - mostly add a few methods etc. Example: Open source lib has classes Map and Layer defined. The relationship between them is one to many. We created our own versions (inherited) of Map...
4
5555
by: l.s.rockfan | last post by:
Hello, how do i have to call an inherited, templated class constructor from the initializer list of the inheriting, non-templated class constructor? example code: template<typename T> class A
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.