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 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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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>
|
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 ...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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
{
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
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 ...
| |