473,473 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

typedef inherited from template spec.


Hi

Please consider the following code:

template <class T>
struct Base;

template <template <typenameclass T, typename P>
struct Base<T<P
{
typedef int Type;
};

template <typename P>
struct Derived:
public Base<Derived<P
{
Type v1;
typename Derived<P>::Type v2;
};

For some reason, the declaration of Derived::v1 doesn't compile, while
the declaration of v2 does, and I can't really understand why. I tested
it with VC++ 8.1 and the online Comeau compiler, the results were the
same.

What's the difference between Type and Derived<P>::Type inside
Derived<P>?

Some additional observations:
1. If I add a typedef int Type; into the primary Base template, then it
compiles with VC++ 8.1, but still won't compile with Comeau. I don't
see how this should change anything (the primary template is still not
used at all), so Comeau's behavior seems to make more sense.
2. If I remove the specialization, both compilers compile this code.

So, could someone explain this to me?
Thanks,

Imre

Sep 12 '06 #1
2 3185

Imre wrote:
Hi

Please consider the following code:

template <class T>
struct Base;

template <template <typenameclass T, typename P>
struct Base<T<P
{
typedef int Type;
};

template <typename P>
struct Derived:
public Base<Derived<P
{
Type v1;
typename Derived<P>::Type v2;
};

For some reason, the declaration of Derived::v1 doesn't compile, while
the declaration of v2 does, and I can't really understand why. I tested
it with VC++ 8.1 and the online Comeau compiler, the results were the
same.

What's the difference between Type and Derived<P>::Type inside
Derived<P>?

Some additional observations:
1. If I add a typedef int Type; into the primary Base template, then it
compiles with VC++ 8.1, but still won't compile with Comeau. I don't
see how this should change anything (the primary template is still not
used at all), so Comeau's behavior seems to make more sense.
2. If I remove the specialization, both compilers compile this code.

So, could someone explain this to me?
Thanks,

Imre
Look up ' dependent names". It is also covered in the FAQ.

Sep 12 '06 #2
Imre wrote:
Hi

Please consider the following code:

template <class T>
struct Base;

template <template <typenameclass T, typename P>
struct Base<T<P
{
typedef int Type;
};

template <typename P>
struct Derived:
public Base<Derived<P
{
Type v1;
typename Derived<P>::Type v2;
};

For some reason, the declaration of Derived::v1 doesn't compile, while
the declaration of v2 does, and I can't really understand why. I tested
it with VC++ 8.1 and the online Comeau compiler, the results were the
same.

What's the difference between Type and Derived<P>::Type inside
Derived<P>?

Some additional observations:
1. If I add a typedef int Type; into the primary Base template, then it
compiles with VC++ 8.1, but still won't compile with Comeau. I don't
see how this should change anything (the primary template is still not
used at all), so Comeau's behavior seems to make more sense.
2. If I remove the specialization, both compilers compile this code.

So, could someone explain this to me?
See these FAQs:

http://www.parashift.com/c++-faq-lit...html#faq-35.18

and

http://womble.decadentplace.org.uk/c...disambiguation

Cheers! --M

Sep 12 '06 #3

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

Similar topics

5
by: Arkadiy Vertleyb | last post by:
Hi all, I am having a problem trying to overload a function template, based on a typedef, such as: template<class T> struct A {}; template<class T>
7
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type ...
2
by: PengYu.UT | last post by:
I have the following sample program, which can convert function object with 1 argument into function object with 2 arguments. It can also do + between function object of the same type. The last...
6
by: Alex | last post by:
Hello people, I am getting errors from VS2003 when working with typedef'ed types. For example, assume that I have a type T, defined in a 3rd party include file based on some condition #if...
5
by: jimmy | last post by:
I am trying to simulate typedef template similar to the suggestion of Herb Sutter in the following article: http://www.gotw.ca/gotw/079.htm However when implementing typedef templates according...
19
by: eiji | last post by:
Hi folks, I found this code in a project: > class TestList : public std::vector<Test> { /*empty!!!*/ }; Basicly this ends up in the same result like > typedef...
5
by: Alan Woodland | last post by:
Hi, I don't think I can't do this directly with standard C++, I've tried all the ways I could think of that make sense and then some. I was wondering if someone had a genius idea how I could...
7
by: Markus Petermann | last post by:
Hello, I have a small problem I want to demonstrate with a small demo program: -------------- Snip -------------- #include <string> namespace {
6
by: year1943 | last post by:
For template <typename Tclass My ; I can define partial spec-ns somewhat like template <typename Tclass My<T*; or template <typename Tclass My<Another<T ; And full spec-n, say template <class...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...
0
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...
0
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 ...

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.