473,804 Members | 3,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about dependent names and typename

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
name so should have typename before it. Both MSVC and GCC fail with
errors like "missing ; before *" which seems to confirm my suspicions.
However, Comeau's online C++ compiler lets it pass successfully, which
makes me question the correctness considering Comeau's reputation as
being compliant.

So is this a quirk of Comeau that they let this through because it's
commonly (mis-)used idiom, or is this GCC and MSVC failing to let
through something they should? Or is the standard ambiguous and they
are just interpreting it differently?

(Comeau also lets through the code with a typename. But I also thought
that in all cases typename was either required or prohibited (so never
optional), which would seem to say that Comeau has to be wrong one way
or the other.)

Nov 28 '06 #1
3 1335

Evan napsal:
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
name so should have typename before it. Both MSVC and GCC fail with
errors like "missing ; before *" which seems to confirm my suspicions.
However, Comeau's online C++ compiler lets it pass successfully, which
makes me question the correctness considering Comeau's reputation as
being compliant.

So is this a quirk of Comeau that they let this through because it's
commonly (mis-)used idiom, or is this GCC and MSVC failing to let
through something they should? Or is the standard ambiguous and they
are just interpreting it differently?

(Comeau also lets through the code with a typename. But I also thought
that in all cases typename was either required or prohibited (so never
optional), which would seem to say that Comeau has to be wrong one way
or the other.)
I think there should be typename. Anyway, I would write it as

template <class T >
class C
{
class Nested
{
Nested *n;
};
};

Nov 28 '06 #2

Evan wrote:
Is the following code legal C++?

template <class T >
class C {
class Nested {
C<T>::Nested *n; // typename???
};
};
You definitely need a typename for sure.
But doesnt the above C<T>::Nested form the non deduced context, which
means T cannot be deduced for these constructs ?
>
My understanding was that C<T>::Nested should be considered a dependent
name so should have typename before it. Both MSVC and GCC fail with
errors like "missing ; before *" which seems to confirm my suspicions.
However, Comeau's online C++ compiler lets it pass successfully, which
makes me question the correctness considering Comeau's reputation as
being compliant.

So is this a quirk of Comeau that they let this through because it's
commonly (mis-)used idiom, or is this GCC and MSVC failing to let
through something they should? Or is the standard ambiguous and they
are just interpreting it differently?

(Comeau also lets through the code with a typename. But I also thought
that in all cases typename was either required or prohibited (so never
optional), which would seem to say that Comeau has to be wrong one way
or the other.)
Nov 28 '06 #3
am******@gmail. com wrote:
Evan wrote:
Is the following code legal C++?

template <class T >
class C {
class Nested {
C<T>::Nested *n; // typename???
};
};

You definitely need a typename for sure.
But doesnt the above C<T>::Nested form the non deduced context, which
means T cannot be deduced for these constructs ?
I have no clue what this even means. :-)

This situation arose because I'm trying to do source-to-source
transformation of C++, and the tool that I'm doing is very buggy. (I
think that this is the first time that the pretty-printing feature has
really been exercised; it's fairly new, and the previous work that's
been done one it has been analyses, so no output required.) A version
of the above where the "C<T>::" was removed (to give what the other
poster suggested, and what most people would write) currently outputs
as the above. I needed to find out if this was an error, partly so I
know how to fix it but mostly just for curiosity.

Thanks for your response (and to the other person who replied and
anyone else who does so in the future with more clarifications or
anything)

Evan
>

My understanding was that C<T>::Nested should be considered a dependent
name so should have typename before it. Both MSVC and GCC fail with
errors like "missing ; before *" which seems to confirm my suspicions.
However, Comeau's online C++ compiler lets it pass successfully, which
makes me question the correctness considering Comeau's reputation as
being compliant.

So is this a quirk of Comeau that they let this through because it's
commonly (mis-)used idiom, or is this GCC and MSVC failing to let
through something they should? Or is the standard ambiguous and they
are just interpreting it differently?

(Comeau also lets through the code with a typename. But I also thought
that in all cases typename was either required or prohibited (so never
optional), which would seem to say that Comeau has to be wrong one way
or the other.)
Nov 28 '06 #4

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

Similar topics

5
1508
by: derek | last post by:
(Message also posted to comp.std.c++) I have just been experimenting with g++ 3.4 and code that I thought was compliant has raised compiler problems. Basically, if we have the following code: #include <iostream> using std::cout;
4
1175
by: Ana Farcas via .NET 247 | last post by:
hello, i have an old library i need to port to .net. the old library is written in visual c++ 6.0 and uses templated classes. if i compile the library (after having gone through the conversion wizard), i get errors with the definitions of the templated classes. below are some examples. template<class base, class client> templated_class_name<base,client>::pointer_to_templated_class_member*...
2
1307
by: adebaene | last post by:
Hello all, I just checked that the following did compile with VC2005 b2, and I think it shouldn't: template <typename T> struct A { typedef int Foo; };
3
2401
by: chriscorbell | last post by:
I'm curious about what appears to be a restriction on using an STL container inside a user-defined template, esp. using an iterator to such a container. It's not clear to me if this is a general template/language restriction, and STL iterator limitation, or if I'm just going about it wrong. I'm declaring a template which uses a std::map to store references to the template type, e.g. template template <typename T>
2
1277
by: sharpblade | last post by:
The title of these Item is "Make header files self-sufficient" There're two examples in this Item: Example 1: Dependent names. Templates are compiled at the point where they are defined, except that any dependent names or types are not compiled until the point where the template is instantiated. This means that a template<class Tclass Widget with a std::deque<Tmember does not incur a compile-time error even when <dequeis not included, as...
0
1425
by: Jim Avera | last post by:
On AIX, a template class containing a nested class which needs to be a friend provokes a warning: (W) A template dependent name that is a type must be qualified with "typename". and method definitons give this warning: (S) The class qualifier "List" contains a circular reference back to "" How can these be avoided?
3
1742
by: mojmir | last post by:
Good morning, i found small difference between gcc and visual studio when looking up a dependent name. Consider: struct Base { template<typename T, typename U> void Implement (T t) { } };
5
1272
by: Christof Warlich | last post by:
Hi, just being curious: Anyone having a clue why the commented lines do not compile? Thanks, Christof class B {
54
3627
by: shuisheng | last post by:
Dear All, I am always confused in using constants in multiple files. For global constants, I got some clues from http://msdn.microsoft.com/en-us/library/0d45ty2d(VS.80).aspx So in header file writing: const double PI = 3.14; Every time using it, include the header file.
0
9706
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
10326
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
10317
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
10075
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
6851
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
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
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
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.