473,808 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Type names defined in base template class not visible in derived class in gcc3.2?

Following is the complete code demonstrating the issue:
=============== ======
cat tt.cc

#include <iostream>

template <class T>
class Base {
public:
typedef T difference_type ;
};

template <class T>
class Derived : public Base<T> {
public:
void test() {
difference_type t = 10;
std::cout << "t is " << t << std::endl;
}
};

int main()
{

Derived<int> d;
d.test();

}
========== end of code =============== =======

This code compiles without warning in g++2.96, MIPSpro C++ Compilers:
Version 7.3.1.1m, Sun WorkShop 6 update 2 C++ 5.3 Patch 111685-10.
However g++3.2 gives warning: implicit typename is deprecated, please
see the documentation for details.

My question: is the warning necessary according to the C++ standard?
While I haven't read the standard carefully enough to answer the
question definitely, the C++PL book gives a similar code in the class
of Checked Iterator (pp. 562-563, 3rd editon):

template<class Cont, class Iter = typename Cont::iterator>
class Check_iter : public iterator_traits <Iter> {
// ....
reference_type operator*() {
// ...

Note the reference_type (rather, reference) is type-defined in the
base template iterator_traits <Iter>, and used directly in the derived
class without prefixing "typename".

One obvious approach to get rid of the g++ warning is to add the
following code in the derived class:

typedef typename Base<T>::differ ence_type difference_type ;
Jul 19 '05 #1
2 2851
James Ying wrote:
Following is the complete code demonstrating the issue:
=============== ======
cat tt.cc #include <iostream>

template <class T>
class Base {
public:
typedef T difference_type ;
};

template <class T>
class Derived : public Base<T> {
public:
void test() {
difference_type t = 10;
std::cout << "t is " << t << std::endl;
}
};

int main()
{

Derived<int> d;
d.test();

}
========== end of code =============== =======

This code compiles without warning in g++2.96, MIPSpro C++ Compilers:
Version 7.3.1.1m, Sun WorkShop 6 update 2 C++ 5.3 Patch 111685-10.
However g++3.2 gives warning: implicit typename is deprecated, please
see the documentation for details.

My question: is the warning necessary according to the C++ standard?
While I haven't read the standard carefully enough to answer the
question definitely, the C++PL book gives a similar code in the class
of Checked Iterator (pp. 562-563, 3rd editon):


I'd say that it should be an error, not just a warning. According to the
definition given in 14.6.2.1/1, name 'difference_typ e' used in the
definition of method 'test()' is not a dependent name. For this reason,
as 14.6/8 says, this name should be looked up is accordance with usual
name lookup rules at the point of template definition. Since class
template B<T> does not participate in this name lookup process (see
14.6.2/3), the name 'difference_typ e' will not be found and the code is
ill-formed. That's actually how Comeau's compiler treats this code - it
issues an error

"ComeauTest .c", line 13: error: identifier "difference_typ e" is undefined
difference_type t = 10;
^
template<class Cont, class Iter = typename Cont::iterator>
class Check_iter : public iterator_traits <Iter> {
// ....
reference_type operator*() {
// ... Note the reference_type (rather, reference) is type-defined in the
base template iterator_traits <Iter>, and used directly in the derived
class without prefixing "typename".
Well, the code in the book can be incomplete or outdated.
One obvious approach to get rid of the g++ warning is to add the
following code in the derived class:

typedef typename Base<T>::differ ence_type difference_type ;


That would be the right thing to do.

--
Best regards,
Andrey Tarasevich
Brainbench C and C++ Programming MVP

Jul 19 '05 #2
Thank you for pointing to the right sections in the standard, and I
agree with you. The standard is pretty clean on this, although it
makes life a bit mroe difficult -- the supposed trick presented in
TC+PL about checked iterator will not do the trick to save a few
typings.
Andrey Tarasevich <an************ **@hotmail.com> wrote in message news:<vp******* *****@news.supe rnews.com>...
James Ying wrote:
Following is the complete code demonstrating the issue:
=============== ======
cat tt.cc

#include <iostream>

template <class T>
class Base {
public:
typedef T difference_type ;
};

template <class T>
class Derived : public Base<T> {
public:
void test() {
difference_type t = 10;
std::cout << "t is " << t << std::endl;
}
};

int main()
{

Derived<int> d;
d.test();

}
========== end of code =============== =======

This code compiles without warning in g++2.96, MIPSpro C++ Compilers:
Version 7.3.1.1m, Sun WorkShop 6 update 2 C++ 5.3 Patch 111685-10.
However g++3.2 gives warning: implicit typename is deprecated, please
see the documentation for details.

My question: is the warning necessary according to the C++ standard?
While I haven't read the standard carefully enough to answer the
question definitely, the C++PL book gives a similar code in the class
of Checked Iterator (pp. 562-563, 3rd editon):


I'd say that it should be an error, not just a warning. According to the
definition given in 14.6.2.1/1, name 'difference_typ e' used in the
definition of method 'test()' is not a dependent name. For this reason,
as 14.6/8 says, this name should be looked up is accordance with usual
name lookup rules at the point of template definition. Since class
template B<T> does not participate in this name lookup process (see
14.6.2/3), the name 'difference_typ e' will not be found and the code is
ill-formed. That's actually how Comeau's compiler treats this code - it
issues an error

"ComeauTest .c", line 13: error: identifier "difference_typ e" is undefined
difference_type t = 10;
^
template<class Cont, class Iter = typename Cont::iterator>
class Check_iter : public iterator_traits <Iter> {
// ....
reference_type operator*() {
// ...

Note the reference_type (rather, reference) is type-defined in the
base template iterator_traits <Iter>, and used directly in the derived
class without prefixing "typename".


Well, the code in the book can be incomplete or outdated.
One obvious approach to get rid of the g++ warning is to add the
following code in the derived class:

typedef typename Base<T>::differ ence_type difference_type ;


That would be the right thing to do.

Jul 19 '05 #3

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

Similar topics

2
2407
by: verec | last post by:
Consider a first version: --- drawable.hpp --- #include "gcdata.hpp" struct drawable { ... virtual int internal_new_GC(gcdata * gcd) = 0 ; } ; --- gcdata.hpp ---
0
1673
by: Arne Claus | last post by:
I've got a tricky problem here. I try to create an object-hierarchie, based on a template base class like template <class T> class Node { addChild(Node<T> *) =0; // the Node-Container wil be defined in the base classes }; The problem is, that the classes derived from Node represent different forms of hierarchies, which all can use a different paramter T. This
1
2280
by: sygnosys | last post by:
Hi, I'm using VC++ 2005 can anyone tell me what's wrong with the following piece of code. It simply does not compile spitting out the following error "error C2039: 'TypeDerived' : is not a member of 'Derived<X>'" template <class X, class Y> class Base { public:
4
2162
by: michael.alexeev | last post by:
Hi all. Consider the following code fragment: #include <string> struct Base{ virtual ~Base() {} }; template <typename T> struct Derived : public Base {}; Base* Create (int param) { switch (param) {
9
1665
by: Mirko Puhic | last post by:
Is there a way to properly do this? struct Derived; struct Base{ Derived der; };
0
2035
by: ivan.leben | last post by:
I am writing this in a new thread to alert that I found a solution to the problem mentioned here: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8 and to avoid this topic getting lost before people interested in the problem notice it. The important tricks to the solution are two: 1) make the custom classes take a TEMPLATE argument which defines their BASE class 2) EMBED the custom classes in a "Traits"...
19
2569
by: n.torrey.pines | last post by:
I have the following tree definition: template<typename T> struct tree { T first; vector<tree<T second; // branches }; which compiles successfully. What I'd like to do though is to use another template like 'pair', because I might have a bunch of useful
33
5088
by: Ney André de Mello Zunino | last post by:
Hello. I have written a simple reference-counting smart pointer class template called RefCountPtr<T>. It works in conjunction with another class, ReferenceCountable, which is responsible for the actual counting. Here is the latter's definition: // --- Begin ReferenceCountable.h ---------- class ReferenceCountable
6
1908
by: Generic Usenet Account | last post by:
I ran a small experiment involving RTTI and dynamic casting. Basically what I did was to cast a base class pointer to a derived type (yes, I know that is not kosher). I then performed dynamic_casting and I invoked RTTI. In both instances, the run time environment did not pick up the fact that what I was claiming to be a derived pointer was in fact the base pointer. However, when I invoked a virtual method using the ostensibly derived...
0
9600
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
10633
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
10375
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,...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6880
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();...
1
4331
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
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
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.