Hello,
Does anyone know why this declaration compiles:
template< template<typenameclass T>
class X { /*...*/ };
while this one doesn't:
template< template<typenametypename T>
class X { /*...*/ };
I thought "class" and "typename" were equivalent in template
declarations?
I don't think it's my compiler's fault (VC8) because I couldn't find
references to syntaxes like the second one on the web, only like the
first one, so there must be a logical reason...
Even Comeau's FAQ uses the first form, without even mentioning the
second one.
Thanks by advance.
--
IR 8 1787
IR wrote:
Hello,
Does anyone know why this declaration compiles:
template< template<typenameclass T>
class X { /*...*/ };
while this one doesn't:
template< template<typenametypename T>
class X { /*...*/ };
I thought "class" and "typename" were equivalent in template
declarations?
They are, but only if you use them alone. What you have here is
a template template argument and you cannot use 'typename' there,
it has to be 'class'. See 14.1/1 for the syntax.
I don't think it's my compiler's fault (VC8) because I couldn't find
references to syntaxes like the second one on the web, only like the
first one, so there must be a logical reason...
Even Comeau's FAQ uses the first form, without even mentioning the
second one.
Because there is no "second one". The syntax rules require "class"
there.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Victor Bazarov wrote:
IR wrote:
[...]
>I thought "class" and "typename" were equivalent in template declarations?
They are, but only if you use them alone. What you have here is
a template template argument and you cannot use 'typename' there,
it has to be 'class'. See 14.1/1 for the syntax.
[...]
Thanks for the answer Victor.
From now on I'll try to look _also_ in the standard before posting
stupid questions on a newsgroup... ;-)
Cheers.
--
IR
In article <Xn**************************@194.177.96.26>,
IR <no******@use.netwrote:
>Does anyone know why this declaration compiles:
template< template<typenameclass T> class X { /*...*/ };
while this one doesn't:
template< template<typenametypename T> class X { /*...*/ };
I thought "class" and "typename" were equivalent in template declarations?
I don't think it's my compiler's fault (VC8) because I couldn't find references to syntaxes like the second one on the web, only like the first one, so there must be a logical reason...
Even Comeau's FAQ uses the first form, without even mentioning the second one.
If I understand you, there is no second one. See revision at: http://www.comeaucomputing.com/techtalk/#typename
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in beta!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
IR wrote:
Hello,
Does anyone know why this declaration compiles:
template< template<typenameclass T>
class X { /*...*/ };
while this one doesn't:
template< template<typenametypename T>
class X { /*...*/ };
I thought "class" and "typename" were equivalent in template
declarations?
No, they are not. In some places they are eqivalent, in others they
are not. You found one of those!
The opposite example is
template<class T, typename T::some_type>
stuct X;
Here, the class keyword can be replaces by typename, but the typename
in the second parameter cannot be replaced by class.
So, using typename in place of class can be confusing!
Bo Persson
Bo Persson wrote:
IR wrote:
[snip]
>I thought "class" and "typename" were equivalent in template declarations?
No, they are not. In some places they are eqivalent, in others
they are not. You found one of those!
The opposite example is
template<class T, typename T::some_type>
stuct X;
Here, the class keyword can be replaces by typename, but the
typename in the second parameter cannot be replaced by class.
Isn't this very example a (non-)dependent name lookup disambiguation?
(or whatever it is called... I guess you get the point anyway :p)
--
IR This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Gianni Mariani |
last post by:
I was a little surprised by this:
It seems like the code below should not compile but the Comeau 4.3.3
compiler accepts it and the gcc 3.4(prerel) compiler rejects it and
MSVC++7.1 ICE's.
...
|
by: Alexander Stippler |
last post by:
Hi,
I have a little problem to design some template classes in a realizable way.
I have some Container classes and some Proxy classes (proxies for
elements). Looks like this:
// P is the...
|
by: Erik Wikström |
last post by:
I've been trying for a while now to understand how template template
parameters work. But I just can't wrap my head around it and was hoping
that someone might help me. As best I can figure the...
|
by: rincewind |
last post by:
Hi,
can anybody summarise all options for partial template specialization,
for all kind of parameters (type, nontype, template)?
I *think* I understand options for partial specialization on...
|
by: Dan Krantz |
last post by:
I have the following template to ensure that a given number (val) falls into
a range (between vmin & vmax):
template<typename T> T ForceNumericRange( const T& val, const T& vmin, const
T& vmax)...
| |
by: Paul Roberts |
last post by:
Hi,
I'm hoping somebody here can help me with a simple problem of template
syntax.
Here's an example:
template<typename T, int iclass A
{
static int a;
|
by: Jess |
last post by:
Hi,
I have a template function that triggered some compiler error. The
abridged version of the class and function is:
#include<memory>
using namespace std;
template <class T>
|
by: Pierre Yves |
last post by:
Hi there,
Sorry for the double subject but I feel they are related. I'm not pretty
sure there would be an answer but I reckon there must be a way to make
it work.
I would like to write the...
|
by: flopbucket |
last post by:
Hi,
I want to provide a specialization of a class for any type T that is a
std::map.
template<typename T>
class Foo
{
// ...
};
|
by: * Tong * |
last post by:
First of all, thanks mlimber for answering my previous question. Now...
I'm following the example in "C++ Templates: The Complete Guide",
section 5.4 Template Template Parameters, and I'm...
|
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: 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...
|
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...
| |