473,794 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

typename missing

vc7.1 has no problem with the following snippet:

template <typename T> class TTest
{
std::list<T*>:: iterator m_It;
};

but metrowerks codewarrior 9.2 kicks my butt and online Comeau confirms:

1. MW:
Warning : 'typename' is missing in template argument dependent qualified
type
Tests.cxx line 52 std::list<typen ame T*>::iterator it;

2. Comeau:
"ComeauTest .c", line 5: error: nontype "std::list< _Tp, _Alloc>::iterat or
[with
_Tp=T *, _Alloc=std::all ocator<T *>]" is not a type name
std::list<T*>:: iterator m_It;
^
There were not that many places to insert "typename", so after a while I
found that the following makes
CW and Comeau happy:

template <typename T> class TTest
{
typename std::list<T*>:: iterator m_It;
};
Can anyone here help me understand this?
regards,
Conrad Weyns


Jul 22 '05 #1
4 2460
Conrad Weyns wrote:
vc7.1 has no problem with the following snippet:

template <typename T> class TTest
{
std::list<T*>:: iterator m_It;
};

but metrowerks codewarrior 9.2 kicks my butt and online Comeau confirms: .... There were not that many places to insert "typename", so after a while I
found that the following makes
CW and Comeau happy:

template <typename T> class TTest
{
typename std::list<T*>:: iterator m_It;
};
Can anyone here help me understand this?


Comeau and MetroWerks are right. The compiler should be checking syntax
when the template definition is first encountered, but at that point it
doesn't yet know (unless you tell it) that dependent_type< T>::iterator
is a type name.
Jul 22 '05 #2

"Conrad Weyns" <we***@online.n o> wrote in message
news:c6******** ***@news.datagu ard.no...
vc7.1 has no problem with the following snippet:

template <typename T> class TTest
{
std::list<T*>:: iterator m_It;
};

but metrowerks codewarrior 9.2 kicks my butt and online Comeau confirms:

1. MW:
Warning : 'typename' is missing in template argument dependent qualified
type
Tests.cxx line 52 std::list<typen ame T*>::iterator it;

2. Comeau:
"ComeauTest .c", line 5: error: nontype "std::list< _Tp, _Alloc>::iterat or
[with
_Tp=T *, _Alloc=std::all ocator<T *>]" is not a type name
std::list<T*>:: iterator m_It;
^
There were not that many places to insert "typename", so after a while I
found that the following makes
CW and Comeau happy:

template <typename T> class TTest
{
typename std::list<T*>:: iterator m_It;
};
Can anyone here help me understand this?
regards,
Conrad Weyns


When the compiler first looks at TTest cannot tell if iterator is a typedef
or a static member in the class std::list<T*>. This is because it does not
know the type of T at this point. It cannot even find this out by looking up
the definition of std::list because there maybe specialisation of std::list
which are not visible while it is first looking at TTest (actually that not
likely to be true for std::list, but it's true of templates in general).

The classic example of why the compiler needs to know if a 'dependant name'
is a typedef or a static member is this

template <typename T>
class Awkward
{
T::some_name * global;
};

Now is that a declaration of a variable called global of type T::some_name,
or is it a multiplication of the static member T::some_name and the global
variable called global?

In general the compiler cannot resolve these ambiguities so you have to do
yourself. Nevertheless in most cases the compiler can work out what you mean
(or at least take a reasonable guess) so many compilers let these things go.

Actually this is the simplest of the syntactic ambiguities introduced by
templates, but I'll not post any others (unless you're particularly
interested) since I'd have to look them up myself.

John
Jul 22 '05 #3
>
template <typename T>
class Awkward
{
T::some_name * global;
};

Now is that a declaration of a variable called global of type T::some_name,

I meant of type T::some_name*
or is it a multiplication of the static member T::some_name and the global
variable called global?


In essence is the * a multiplication or does it indicate a pointer?

john
Jul 22 '05 #4

"John Harrison" <jo************ *@hotmail.com> wrote in message
news:c6******** ****@ID-196037.news.uni-berlin.de...

"Conrad Weyns" <we***@online.n o> wrote in message
news:c6******** ***@news.datagu ard.no...
vc7.1 has no problem with the following snippet:

template <typename T> class TTest
{
std::list<T*>:: iterator m_It;
};

but metrowerks codewarrior 9.2 kicks my butt and online Comeau confirms:

1. MW:
Warning : 'typename' is missing in template argument dependent qualified
type
Tests.cxx line 52 std::list<typen ame T*>::iterator it;

2. Comeau:
"ComeauTest .c", line 5: error: nontype "std::list< _Tp, _Alloc>::iterat or
[with
_Tp=T *, _Alloc=std::all ocator<T *>]" is not a type name
std::list<T*>:: iterator m_It;
^
There were not that many places to insert "typename", so after a while I
found that the following makes
CW and Comeau happy:

template <typename T> class TTest
{
typename std::list<T*>:: iterator m_It;
};
Can anyone here help me understand this?
regards,
Conrad Weyns

When the compiler first looks at TTest cannot tell if iterator is a

typedef or a static member in the class std::list<T*>. This is because it does not
know the type of T at this point. It cannot even find this out by looking up the definition of std::list because there maybe specialisation of std::list which are not visible while it is first looking at TTest (actually that not likely to be true for std::list, but it's true of templates in general).

The classic example of why the compiler needs to know if a 'dependant name' is a typedef or a static member is this

template <typename T>
class Awkward
{
T::some_name * global;
};

Now is that a declaration of a variable called global of type T::some_name, or is it a multiplication of the static member T::some_name and the global variable called global?

In general the compiler cannot resolve these ambiguities so you have to do
yourself. Nevertheless in most cases the compiler can work out what you mean (or at least take a reasonable guess) so many compilers let these things go.
Actually this is the simplest of the syntactic ambiguities introduced by
templates, but I'll not post any others (unless you're particularly
interested) since I'd have to look them up myself.

John
Many thanks, this has been usefull. I know what to play with now to get a
better mental picture of this.
Conrad

Jul 22 '05 #5

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

Similar topics

1
3853
by: I wish | last post by:
I wrote some test code template <typename T> class A {}; class B{}; template < template <typename T> typename U > class C {}; int main( void )
2
2699
by: Chris Foster | last post by:
Hi, I'm having some difficulty using types which are defined in a base class inside a derived class. The problem crops up using template classes. The following test code encapsulates what I'd like to do, but doesn't compile with g++ (v3.3.3). //--------------------------------------------------------- // A = base class template <typename T>
3
1894
by: Šimon Tóth | last post by:
Can anybody tell me how to turn of this warning? -Wno-deprecated doesn't work. I don't want to edit the source file, because it works fine and it's a bit hardcore stuff for me :) warning: implicit typename is deprecated, please see the documentation for details
1
1770
by: lutorm | last post by:
Hi all, I'm working on migrating my code from KCC to gcc, and I'm having some issues with "implicit typename" warnings from gcc. Essentially, what happens is described by this example: template <typename cell_data_type> class cell {}; template <typename a> class c1 { public: typedef cell<a> T_cell;
13
1716
by: Staffan Langin | last post by:
Hello, In the following code-snippet, template<class Base> class Foo : public Base {
8
1778
by: xuatla | last post by:
Hi, When I compile the following test code I got a warning about implicit typename. This happens in the member functions. Do you know the detail reason and solution? Thanks. - X ----------
2
1909
by: Dilip | last post by:
Folks I understand that the keyword typename is also used to indicate that a dependant parameter is a type. However I am a little unsure why I need typename in this following example: template<typename K, typename V> class MyMap { public:
3
1335
by: Evan | last post by:
Is the following code legal C++? template <class T > class C { class Nested { C<T>::Nested *n; // typename??? }; }; My understanding was that C<T>::Nested should be considered a dependent
7
2127
by: StephQ | last post by:
First of all: distinction of keywords typename and class in template arguments. Accoarding to a post in a well known moderated group: "There are three possibilities for template arguments: 1) type as in "template <typename T>" or "template <class T>" 2) non-type as in "template <int N>" 3) class template as in "template <template<typenameclass C>" "
0
9671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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
10212
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10161
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
10000
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
9035
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...
1
7538
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
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2919
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.